Debugging Memory Problems with MemoryScape™ : Chapter 2 Memory Tasks : Task 3: ­Setting MemoryScape Options : Advanced Options : Guard allocated memory
Guard allocated memory
When your program allocates a memory block, MemoryScape can write additional memory segments both before and after the block. These segments are called guards. Immediately after creating the guards, MemoryScape initializes them to a bit pattern.
These guards can help you identify corrupted memory in two ways:
When your program deallocates a memory block, MemoryScape checks to determine if the pattern differs from when it first wrote the block. If so, your program will have overwritten memory that it shouldn’t have used. This indicates that memory was corrupted. (MemoryScape writes one pattern into the guard preceding a block and another into the one after it.)
Whenever you halt execution, you can ask MemoryScape to check for corrupted guard blocks, which looks at all guard blocks surrounding your allocations.
For information on guard blocks, see Task 11: "Viewing Corrupted Memory".
Enable guard blocks by selecting either a level of Medium or selecting the check box in the Advanced screen. Figure 46 shows the portion of that screen that controls guard blocks.
 
Figure 46: Guard allocated memory Option
These options control the size of guard blocks and their pattern.
You can also set a maximum size for the guard blocks that surround a memory allocation. This can be useful because the size actually used for a guard block can be greater than the pre-guard and post-guard sizes due to the way an operating system aligns information. If memory is tight, setting a value here ensures that blocks do not use an excessive amount of memory.
If the value is set to zero (0), which is the default, MemoryScape does not set a maximum size.