perform a consistency check for a heap
#include <malloc.h> int _heapchk( void ); int _bheapchk( __segment seg ); int _fheapchk( void ); int _nheapchk( void );
The _heapchk() functions, along with _heapset() and _heapwalk(), are provided for debugging heap-related problems in programs.
The _heapchk() functions perform a consistency check on the unallocated memory space or heap. The consistency check determines whether or not all the heap entries are valid. Each function checks a particular heap, as listed below:
In a small data memory model, the _heapchk() function is equivalent to the _nheapchk() function; in a large data memory model, the _heapchk() function is equivalent to the _fheapchk() function.
All four functions return one of the following manifest constants, which are defined in <malloc.h>:
#include <stdio.h> #include <malloc.h> void main() { char *buffer; buffer = (char *)malloc( 80 ); malloc( 1024 ); free( buffer ); switch( _heapchk() ) { case _HEAPOK: printf( "OK - heap is good\n" ); break; case _HEAPEMPTY: printf( "OK - heap is empty\n" ); break; case _HEAPBADBEGIN: printf( "ERROR - heap is damaged\n" ); break; case _HEAPBADNODE: printf( "ERROR - bad node in heap\n" ); break; } }
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
_heapenable(), _heapgrow(), _heapmin(), _heapset(), _heapshrink(), _heapwalk()