void MemRem(I1 *msg) { #if( __TURBOC__ >= 0x295 ) struct heapinfo hp; // heap information U4 bytes = coreleft(); fprintf(_ulog, "%s:\n", msg); fprintf(_ulog, " Unallocated heap memory: %ld bytes\n", bytes); # if( MEMTEST > 1 ) switch(heapcheck()) { case _HEAPEMPTY: fprintf(_ulog, "The heap is empty.\n"); break; case _HEAPOK: fprintf(_ulog, "The heap is O.K.\n"); break; case _HEAPCORRUPT: fprintf(_ulog, "The heap is corrupted.\n"); break; } // end switch fprintf(_ulog, "Heap: loc, size, used?\n"); hp.ptr = NULL; while(heapwalk(&hp) == _HEAPOK) { fprintf(_ulog, "[%p]%8lu %s\n", hp.ptr, hp.size, hp.in_use ? "used" : "free"); } # endif }
void dbg_printmem(void) { static unsigned nearLast = 0; static unsigned long farLast = 0; unsigned nearThis; unsigned long farThis; switch(heapcheck()) { case _HEAPCORRUPT: cputs("HEAP CORRUPTED. Cannot proceed!\r\n"); abort(); case _HEAPEMPTY: cputs("NO HEAP. Cannot proceed!\r\n"); abort(); default: cputs("Unknown heapcheck() error. Cannot proceed!\r\n"); abort(); case _HEAPOK: break; } nearThis = coreleft(); farThis = farcoreleft(); dprintf(("[free memory: near=%6u far=%13lu]\n", nearThis, farThis)); if(nearLast) dprintf(("[changed : near=%6d far=%13ld]\n" , nearThis - nearLast , farThis - farLast)); nearLast = nearThis; farLast = farThis; }
void suppl_testHeap(void) { if(heapcheck() != _HEAPOK) { cputs("\r\nHeap corrupted\r\nPress any key to terminate application\r\n"); getch(); DBG_TERMINATE("Heap corrupted"); } }
callStack::~callStack() { if (heapcheck() != _HEAPOK) { fprintf(stderr, "Heap check failed on exit\n"); dump(); exit(3); } if (root) { root = root->next; } free(name); }
callStack::callStack(CPCHAR fileName, const long lineNo) { if (heapcheck() != _HEAPOK) { fprintf(stderr, "Heap check failed on entry\n"); dump(); exit(3); } this->next = root; root = this; char tmp[128]; sprintf(tmp, "%s @ %ld", fileName, lineNo); name = strdup(tmp); }