Debug versions are available for both regular memory management functions and user-defined heap memory management functions. Each debug version performs the same function as its non-debug counterpart, and you can use them for any type of heap, including shared memory. Each call you make to a debug function also automatically checks the heap by calling _heap_check (described below), and provides information, including file name and line number, that you can use to debug memory problems. The names of the user-defined debug versions are prefixed by _debug_u (for example, _debug_umalloc), and they are defined in umalloc.h.
For a complete list and details about all of the debug memory management functions, see Memory debug library functions.
| Default heap function | Corresponding user-created heap function |
|---|---|
| _debug_calloc | _debug_ucalloc |
| _debug_malloc | _debug_umalloc |
| _debug_heapmin | _debug_uheapmin |
| _debug_realloc | n/a |
| _debug_free | n/a |
To compile an application that calls the user-created heap functions, see Compiling and linking a program with user-created heaps.
Three additional debug memory management functions do not have regular counterparts. They are summarized in the following table.
| Default heap function | Corresponding user-created heap function | Description |
|---|---|---|
| _dump_allocated | _udump_allocated | Prints information to stderr about each memory block currently allocated by the debug functions. |
| _dump_allocated_delta | _udump_allocated_delta | Prints information to file descriptor 2 about each memory block allocated by the debug functions since the last call to _dump_allocated or _dump_allocated_delta. |
| _heap_check | _uheap_check | Checks all memory blocks allocated or freed by the debug functions to make sure that no overwriting has occurred outside the bounds of allocated blocks or in a free memory block. |
The _heap_check function is automatically called by the debug functions; you can also call this function explicitly. You can then use _dump_allocated or _dump_allocated_delta to display information about currently allocated memory blocks. You must explicitly call these functions.