INF: _heapchk() Performs Consistency Check on Heap

ID Number: Q32442

5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a

MS-DOS | OS/2

Summary:

In Microsoft C versions 5.1, 6.0, 6.0a, 6.0ax, and C/C++ version 7.0,

the _heapchk() routine performs a consistency check on the heap by

examining the header information of the memory blocks in the heap; it

cannot, however, detect corruption of data within the heap's nodes.

The _heapchk routine can only detect corruption of the heap's header

information.

The _heapchk() routine checks for the following:

- It checks to see if any heap has been allocated. If not, _heapchk()

returns _HEAPEMPTY.

- It checks the beginning of the heap block to see if the first

allocation block has been corrupted; if so, it returns

_HEAPBADBEGIN. (Note that only the header information is checked.)

- It scans through the far heap block, moving from node to node. For

each node, it checks the header information to make sure it has not

been corrupted; if so, _heapchk() returns _HEAPBADNODE. Note that

the only kind of corruption _heapchk() can detect is an

out-of-bounds value in the header; it cannot detect corrupted data

within the heap block itself. If the fill value passed is not

_HEAPSET_NOFILL, and the block is unallocated, _heapchk() fills

memory with the fill value.

- If _heapchk() makes it all the way through the heap (that is, it

checks the headers for all nodes), it returns _HEAPOK.

More Information:

Microsoft C versions 6.0 and later also provide the _heapwalk()

functions, which can aid in debugging memory allocation problems. More

information on the _heapwalk() function may be found in the online

help provided with Microsoft C version 6.0.

Additional reference words: 6.0 6.00 6.0a 6.00a 6.0ax 6.00ax 7.00