These functions provide information that you can use to debug memory problems. Use them to allocate and free memory from the default run-time heap, just as you would use the regular versions. In addition to their usual behavior, these functions store information (file name and line number) about each call made to them. Each call also automatically checks the heap by calling _heap_check.
When you use the /Tm compiler option, all calls to the regular memory management functions are mapped to their debug versions. You can also call the debug versions explicitly. If you parenthesize the calls to the regular memory management functions, they are not mapped to their debug versions.
If you have already compiled, and do not want to recompile, but still need to determine if any heap errors are present, you can relink your application with the /DEBUG linker option and cpphd.obj. This will give output similar to compiling with /Tm+, but will not include filenames or lines. Instead, tracebacks are given.
By default, strings are read-only (default setting is #pragma strings(readonly)). It is not essential that you use this directive, but it does ensure that the file name passed to the debug functions cannot be overwritten, and that only one copy of the file name string is included in the object module.
The names of the debug versions are prefixed by _debug_, for example, _debug_malloc, and they are defined in <malloc.h> and <stdlib.h>
The functions provided are:
Three additional debug memory management functions do not have regular counterparts:
![]()
Types of Memory
Memory
Management Functions