_heapchk

Runs consistency checks on the heap.

int _heapchk( void );

Routine Required Header Optional Headers Compatibility
_heapchk <malloc.h> <errno.h> Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_heapchk returns one of the following integer manifest constants defined in MALLOC.H:

_HEAPBADBEGIN

Initial header information is bad or cannot be found

_HEAPBADNODE

Bad node has been found or heap is damaged

_HEAPBADPTR

Pointer into heap is not valid

_HEAPEMPTY

Heap has not been initialized

_HEAPOK

Heap appears to be consistent

In addition, if an error occurs, _heapchk sets errno to ENOSYS.

Remarks

The _heapchk function helps debug heap-related problems by checking for minimal consistency of the heap.

Example

/* 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;
   }
}

Output

OK - heap is fine

Memory Allocation Routines

See Also   _heapadd, _heapmin, _heapset, _heapwalk