Memory Debug Codes
Microsoft's memory management functions often initialize memory with special values. The following article describes frequent used variants.
Microsoft Visual C++ Runtime library
C runtime library provides it own debug codes:
- New objects. New objects are filled with 0xCD when they are allocated.
- No-man's land memory. Extra bytes that belong to the internal block allocated, but not the block you requested. They are placed before and after requested blocks and used for data bound checking.
- Freed blocks. The freed blocks kept unused in the debug heap's linked list when the _CRTDBG_DELAY_FREE_MEM_DF flag is set are currently filled with 0xDD. Although in some cases you won't see magic 0xDDDDDDDD value, as it will be overwritten by another debug function (e.g. 0xFEEEFEEE for HeapFree).
These constants are defined in DbgHeap.c
static unsigned char _bNoMansLandFill = 0xFD; /* fill no-man's land with this */
static unsigned char _bDeadLandFill = 0xDD; /* fill free objects with this */
static unsigned char _bCleanLandFill = 0xCD; /* fill new objects with this */
- The /GX Microsoft Visual C++ compiler option initialises all local variables not explicitly initialised by the program. It fills all memory used by these variables with 0xCC, 0xCCCCCCCC.
Windows NT memory codes
- Memory following a block allocated by LocalAlloc().
- "Bad Food". This is memory allocated via LocalAlloc( LMEM_FIXED, ... ). It is memory that has been allocated but not yet written to.
- OS fill heap memory, which was marked for usage, but wasn't allocated by HeapAlloc() or LocalAlloc(). Or that memory just has been freed by HeapFree().
Thanks to Samuel R. Blackburn, especially for Windows NT codes
Revision:1, Last Modified: 05/14/01 18:07, by Vadim Melnik
Visit my Homepage
How to create ReleaseDebug configuration for Microsoft Visual C++ 6.0 projects?
It�s good style to ship your compiled binaries with turned on program database debug support. The main differences between ReleaseDebug and Release configurations is only ten bytes at the and of file, that contains path to PDB file. Benefits for such build are ability to debug release configuration under debugger and possibility to fix program crash without recompilation (I�d recommend to store PDB files for each builds as well as sources).
Here are steps to make ReleaseDebug configuration from Release one:
1) In �Project Setting� dialog, open �Link� pane and select �Generate debug info� checkbox.
2) Right here add �/opt:ref� switch in the �Project Options� edit box.
3) Open �C/C++� tab and select from �Debug info� combobox �Program Database� option.
Revision:1, Last Modified: 05/14/01 22:32, by Vadim Melnik
Visit my Homepage