After your program allocates memory, you must make sure that it does not write data outside the allocated block. MemoryScape can help you detect these kinds of problems by surrounding memory allocations with a small amount of additional memory. These additional memory blocks are called <i>guard blocks</i>. If your program overwrites these blocks, MemoryScape can tell that a problem occurred in two ways:<ul><li>You can create a <b>Corrupted Memory Report</b>. This information is also available in Heap Status reports and other places. However, in these places, you really have to know what to look for.
<li>When your program deallocates memory, the Memory Debugger can check the deallocated block's guards. If they were violated--that is, your program wrote data into them--MemoryScape stops execution and notifies you about the violation.</ul>For example, suppose the program allocates 16 bytes and then writes 64 bytes of data. While the first 16 bytes are correctly written, the remaining 48 aren't. The program will have overwritten the guard blocks for both blocks and some of the next block's data. That is, it will have inadvertently changed data, data that when accessed is incorrect.
<p>Using guard blocks to detect problems is usually an interactive process. Asking for notification when the block is deallocated lets you know that a problem has occurred. Because you now know where the block was corrupted, you can use this as a starting point to locate the cause of the problem. In many cases, you will rerun your program, focusing on those blocks.
<p>You can periodically stop execution, checking for guard corruption. This will help you locate where your program is corrupting data.