Format
#include <umalloc.h> void _udump_allocated(Heap_t heap, int nbytes);
Language Level: Extension
For the heap you specify, _udump_allocated prints
information to stderr about each memory block that is currently
allocated and was allocated using the debug memory management
functions (_debug_ucalloc, _debug_umalloc, and so on).
_udump_allocated works just like _dump_allocated, except that you specify the heap to use; _dump_allocated always displays information about the default heap.
Use nbytes to specify how many bytes of each memory block are to be printed. If nbytes is:
| Negative value | Prints all bytes of each block. |
| 0 | Prints no bytes. |
| Positive value | Prints the specified number of bytes or the entire block, whichever is smaller. |
_udump_allocated prints the information to stderr by default. You can change the destination with the _set_crt_msg_handle function.
Call _udump_allocated at points in your code where you want a report of the currently allocated memory. For example, a good place to call _udump_allocated is a point where most of the memory is already freed and you want to find a memory leak, such as at the end of a program.
You can also use _udump_allocated_delta to display information about only the memory that was allocated since the previous call to _udump_allocated or _udump_allocated_delta.
To use _udump_allocated and the debug versions of the memory management functions, specify the debug memory (/Tm) compiler option.
Note: The /Tm option maps all calls to memory management functions (including a heap-specific version) to their debug counterparts. To prevent a call from being mapped, parenthesize the function name.
Return Value
There is no return value. Passing _udump_allocated a
heap that is not valid results in undefined behavior.
Example
This example creates a heap, performs some operations on
it, and then calls _udump_allocated to print out information
about the allocated memory blocks.
Note: You must compile this example with the /Tm option to enable the debug memory management functions.
#include <stdlib.h> #include <stdio.h> #include <umalloc.h> #include <string.h>
int main(void)
{
Heap_t myheap;
char *ptr;
/* Use default heap as user heap */ myheap = _udefault(NULL);
if (NULL == (ptr = (char*)_umalloc(myheap, 10))) {
puts("Cannot allocate memory from user heap.");
exit(EXIT_FAILURE);
}
memset(ptr, 'a', 5);
_udump_allocated(myheap, 10);
free(ptr); return 0;
/****************************************************************************
The output should be similar to :
--------------------------------------------------------------------------
START OF DUMP OF ALLOCATED MEMORY BLOCKS
--------------------------------------------------------------------------
Address: 0x00073890 Size: 0x0000000A (10)
This memory block was (re)allocated at line number 14 in _udump_alloc.c.
Memory contents: 61616161 61AAAAAA AAAA [aaaaaªªªªª ]
--------------------------------------------------------------------------
END OF DUMP OF ALLOCATED MEMORY BLOCKS
--------------------------------------------------------------------------
****************************************************************************/
}
![]()
Managing Memory
with Multiple Heaps
Memory Management
![]()
_debug_ucalloc -- Allocate and Initialize
Memory from User Heap
_debug_umalloc -- Reserve Memory
Blocks from User Heap
_debug_realloc -- Reallocte Memory
Block
_debug_free -- Release Memory
_dump_allocated -- Get Information
about Allocated Memory
_set_crt_msg_handle -- Change Runtime
Message Output Destination
_udump_allocated_delta -- Get
Information about Allocated Memory in Heap
<umalloc.h>
/Tm compiler option