Borland C++ reference

heapwalk

raw OCR

heapwalk is used to "walk" through the heap, node by node.

Defined in header <alloc.h>

Syntax

#include <alloc.h>
int heapwalk(struct heapinfo *hi);

Portability

DOSUNIXWindowsANSI CC++ only
■

Remarks

heapwalk assumes the heap is correct. Use heapcheck to verify the heap

before using heapwalk. _HEAPOKis returned with the last block on the
heap. _HEAPENDwill be returned on the next call to heapwalk.

heapwalk receives a pointer to a structure of type heapinfo (declared in alloc.h). For the first call to heapwalk, set the hi.ptr field to null, heapwalk returns with hi.ptr containing the address of the first block, hi.size holds the size of the block in bytes. hi.in_use is a flag that's set if the block is currently in use.

Return value

The return values and their meaning is as follows:

_HEAPEMPTYno heap (value 1).
_HEAPOKheapinfo block contains valid data (value 2).
_HEAPENDend of the heap has been reached (value 5).

See also

Example

include  <stdio.h>
#include <alloc.h>

Mefine  NUM_PTRS  1(
#define NUM_BYTES U
int main{ void )

   struct heapinfo hi;
   char *array [ NUM_PTRS ] ;
   int i;

   for( i = 0; i < NUM_PTRS; i++  )
      array [ i ] = (char *) malloc( NUM_BYTES );
   for{ i = 0; i < NUM_PTRS;  i += 2 )
      free( array [ i ] );

   hi.ptr = NULL;
   printf( "   Size   Status\n"  );
   printf( "                 \n" );
   while( heapwalk { &hi ) == _HEAPOK )
   printf( "%7u    %s\n", hi.size,  hi.in_use ? "used" : "free"
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.