Format
#include <umalloc.h>
int _uheap_walk(Heap_t heap, int (*callback_fn)(const void *object,
size_t size, int flag, int status,
const char* file, int line) );
Language Level: Extension
_uheap_walk traverses the heap you
specify, and, for each allocated or freed object, it calls the callback_fn
function that you provide. _uheap_walk works just like
_heap_walk, except that you specify the heap to be traversed;
_heap_walk always traverses the default heap.
For each object, _uheap_walk passes your function:
| object | A pointer to the object. | |
| size | The size of the object. | |
| flag | The value _USEDENTRY, if the object is currently allocated, or _FREEENTRY, if the object has been freed. (Both values are defined in <malloc.h>.) | |
| status | One of the following values, defined in both <umalloc.h> and <malloc.h>, depending on the status of the object: | |
| _HEAPBADBEGIN | The heap specified is not valid. It may have been closed or destroyed. | |
| _HEAPBADNODE | A memory node is corrupted, or the heap is damaged. | |
| _HEAPEMPTY | The heap has not been initialized. | |
| _HEAPOK | The heap appears to be consistent. | |
| file | The name of the file where the object was allocated or freed. | |
| line | The line where the object was allocated or freed. | |
_uheap_walk provides information about all objects, regardless of which memory management functions were used to allocate them. However, the file and line information are only available if the object was allocated and freed using the debug versions of the memory management functions. Otherwise, file is NULL and line is 0.
_uheap_walk calls callback_fn for each object until one of the following occurs:
You may want to code your callback_fn to return a nonzero value if the status of the object is not _HEAPOK. Even if callback_fn returns 0 for an object that is corrupted, _heap_walk cannot continue because of the state of the heap and returns to its caller.
You can use callback_fn to process information from _uheap_walk in various ways. For example, you may want to print the information to a file, or use it to generate your own error messages. You can use the information to look for memory leaks and objects incorrectly allocated or freed from the heap. It can be especially useful to call _uheap_walk when _uheapchk returns an error.
Notes:
Return Value
_uheap_walk returns the last value of status
to the caller.
![]()
Managing
Memory with Multiple Heaps
Memory
Management
![]()
_heapmin -- Release Unused
Memory from Default Heap
_heap_walk --
Return Information about Default Heap
_uheapchk --
Validate Memory Heap
_uheapset --
Validate and Set Memory Heap
<umalloc.h>