Tuesday, April 1, 2008

Detect Heap Corruption -- Using CrtCheckMemory()

To debug code that caused heap corruption,We normally do struggle against the computer in order to understand what causes the corruption and how.
In the search for memory validation APIs I have found _CrtCheckMemory() API which is being used by debug version of C run-time libraries. Using this API wrapped with an assert macro gives us the opportunity to check the heap every few lines of code without any overhead in release version: _ASSERTE( CrtCheckMemory());
it would be smart idea to use it even without any visible corruption, it saves time in the long run . This tip is based on information written on the MSDN.