This example allocates some memory and calls _dump_allocated to print information about the allocated blocks. It then allocates more memory, and calls _dump_allocated_delta again to print information about the allocations since the previous call.
Note: You must compile this example with the /Tm option to map the memory management functions to their debug versions.
#include <stdlib.h> #include <stdio.h> #include <string.h>
int main(void)
{
char *ptr1, *ptr2;
if (NULL == (ptr1 = (char*)malloc(10))) {
puts("Could not allocate memory block.");
exit(EXIT_FAILURE);
}
memset(ptr1, 'a', 5);
_dump_allocated(10);
if (NULL == (ptr2 = (char*)malloc(20))) {
puts("Could not allocate memory block.");
exit(EXIT_FAILURE);
}
memset(ptr2, 'b', 5);
_dump_allocated_delta(10);
free(ptr1); free(ptr2); 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 9 in _dump_alloc_d.c.
Memory contents: 61616161 61AAAAAA AAAA [aaaaaªªªªª ]
-------------------------------------------------------------------------------
END OF DUMP OF ALLOCATED MEMORY BLOCKS
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
START OF DUMP OF ALLOCATED MEMORY BLOCKS
-------------------------------------------------------------------------------
Address: 0x000738D0 Size: 0x00000014 (20)
This memory block was (re)allocated at line number 16 in _dump_alloc_d.c.
Memory contents: 62626262 62AAAAAA AAAA [bbbbbªªªªª ]
-------------------------------------------------------------------------------
END OF DUMP OF ALLOCATED MEMORY BLOCKS
-------------------------------------------------------------------------------
****************************************************************************/
}