Run consistency checks on the heap.
#include <malloc.h>
int _heapchk( void );
int _bheapchk( __segment seg );
int _fheapchk( void );
int _nheapchk( void );
seg | Specified base heap |
The _heapchk routines help to debug heap-related problems by checking for minimal consistency of the heap. Each function checks a particular heap, as listed below:
Function | Heap Checked |
_heapchk | Depends on data model of program |
_bheapchk | Based heap specified by seg value |
_fheapchk | Far heap (outside the default data segment) |
_nheapchk | Near heap (inside the default data segment) |
In large data models (that is, compact-, large-, and huge-model programs), _heapchk maps to _fheapchk. In small data models (tiny-, small-, and medium-model programs), _heapchk maps to _nheapchk.
For _heapchk, if the seg value is _NULLSEG, all based heap segments are checked; otherwise, only the specified one is checked.
All four routines return an integer value that is one of the following manifest constants (defined in MALLOC.H):
Constant | Meaning |
_HEAPBADBEGIN | Initial header information cannot be found, or it is bad. |
_HEAPBADNODE | Bad node has been found, or the heap is damaged. |
_HEAPEMPTY | Heap has not been initialized. |
_HEAPOK | Heap appears to be consistent. |
_heapchk
Standards:None
16-Bit:DOS
32-Bit:DOS32X
_bheapchk, _fheapchk
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
_nheapchk
Standards:None
16-Bit:DOS
32-Bit:None
_heapset functions, _heapwalk functions
/* HEAPCHK.C: This program checks the heap for consistency
* and prints an appropriate message.
*/
#include <malloc.h>
#include <stdio.h>
void main( void )
{
int heapstatus;
char *buffer;
/* Allocate and deallocate some memory */
if( (buffer = (char *)malloc( 100 )) != NULL )
free( buffer );
/* Check heap status */
heapstatus = _heapchk();
switch( heapstatus )
{
case _HEAPOK:
printf(" OK - heap is fine\n" );
break;
case _HEAPEMPTY:
printf(" OK - heap is empty\n" );
break;
case _HEAPBADBEGIN:
printf( "ERROR - bad start of heap\n" );
break;
case _HEAPBADNODE:
printf( "ERROR - bad node in heap\n" );
break;
}
}
OK - heap is fine