home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_09_04
/
9n04077a
< prev
next >
Wrap
Text File
|
1991-02-18
|
1KB
|
51 lines
/********************************************************************/
/* Check class allocation errors. Copyright by Joe Schell 1989. */
/********************************************************************/
#ifndef CLASS_check_heap
#define CLASS_check_heap
#include <iostream.h>
#include <stddef.h> // Used for ptrdiff_t definition.
// CHECK_HEAP_diff_: Used get around segmented memory on IBMs.
#if defined(__TURBOC__) \
&& (defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__))
#define CHECK_HEAP_diff_ char huge *
#else
#define CHECK_HEAP_diff_ char*
#endif
class check_heap
{
public:
void start() { begin = new char; delete begin; }
check_heap() { start(); }
void test(const char *s=0) // Do a test.
{
end = new char;
if (begin != end)
cerr << s
<< "Heap error: entry/exit difference = "
<< diff() << ".\n";
delete end;
}
void testnew(const char *s=0) // Do a test and reset.
{ test(s); start(); }
private:
char *begin, *end; // Beginning and end of allocation.
ptrdiff_t diff() const
{ return (ptrdiff_t)
((CHECK_HEAP_diff_)end - (CHECK_HEAP_diff_)begin);}
}; // End of check_heap class.
#endif