Header File
malloc.h
Category
Memory Routines
Prototype
int _rtl_heapwalk(_HEAPINFO *hi);
Description
Inspects the heap node by node.
_rtl_heapwalk receives a pointer to a structure of type _HEAPINFO (declared in malloc.h). Note that the _HEAPINFO structure must be allocated on the heap (using malloc()). You can’t pass the address of a variable declared on the stack.
For the first call to _rtl_heapwalk, set the hi._pentry field to NULL. _rtl_heapwalk returns with hi._pentry containing the address of the first block.
hi._size |
holds the size of the block in bytes. |
hi._useflag |
is a flag that is set to _USEDENTRY if the block is currently in use. If the block is free, hi._useflag is set to _FREEENTRY. |
Return Value
This function returns one of the following values:
_HEAPBADNODE |
A corrupted heap block has been found |
_HEAPBADPTR |
The _pentry field does not point to a valid heap block |
_HEAPEMPTY |
No heap exists |
_HEAPEND |
The end of the heap has been reached |
_HEAPOK |
The _heapinfo block contains valid information about the next heap block |
Example
#include <stdio.h> #include <malloc.h> #include <alloc.h> #define NUM_PTRS 10 #define NUM_BYTES 16 int main( void ) { _HEAPINFO *hi; char *array[ NUM_PTRS ]; int i; hi = (_HEAPINFO *) malloc( sizeof(_HEAPINFO) ); 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->_pentry = NULL; printf( " Size Status\n" ); printf( " ---- ------\n" ); while( _rtl_heapwalk( hi ) == _HEAPOK ) printf( "%7u %s\n", hi->_size, hi->_useflag ? "used" : "free" ); free( hi ); return 0; }
Portability
POSIX |
Win32 |
ANSI C |
ANSI C++ |
|
+ |
|
|
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|