Category : C Source Code
Archive   : LITE286.ZIP
Filename : MEMTEST2.CPP

 
Output of file : MEMTEST2.CPP contained in archive : LITE286.ZIP
/*
MEMTEST2.CPP
bcc286 memtest2.cpp
*/

#include
#include
#include
#include

class msg {
public:
msg() { cout << "hello from " << __FILE__ << "\n" ; }
~msg() { cout << "bye\n" ; }
} ;

static msg banner; // test C++ static constructors, destructors

static unsigned long bytes = 0;
static unsigned long allocs = 0;
static unsigned blk_size = 10240;

#ifdef _MSC_VER
#pragma warning(disable:4100)
int new_fail(size_t size)
{
if (blk_size)
blk_size >>= 1; // try to allocate a smaller block
else
{ // memory exhausted
cout << "Allocated " << bytes << " bytes\n" ;
exit(1);
}
return 1;
}
#pragma warning(default:4100)
#else
#define _set_new_handler set_new_handler
void new_fail(void)
{
if (blk_size)
blk_size >>= 1; // try to allocate a smaller block
else
{ // memory exhausted
cout << "Allocated " << bytes << " bytes\n" ;
exit(1);
}
}
#endif

void
main(void)
{
char *p;

_set_new_handler(new_fail); // called when new fails

for (;;)
{
p = new char[blk_size]; // allocate memory
memset(p, 0, blk_size); // touch every byte
*p = 'x'; // do something, anything with
p[blk_size-1] = 'y'; // the allocated memory

bytes += blk_size;
allocs++;
if ((allocs % 25) == 0) // odometer
cout << "Allocated " << bytes << " bytes\r";
}
}


  3 Responses to “Category : C Source Code
Archive   : LITE286.ZIP
Filename : MEMTEST2.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/