_CrtCheckMemory

Confirms the integrity of the memory blocks allocated in the debug heap (debug version only).

Syntax


int _CrtCheckMemory( void );

Return value

If successful, _CrtCheckMemory returns TRUE; otherwise, the function returns FALSE.

Remarks

The _CrtCheckMemory function validates memory allocated by the debug heap manager by verifying the underlying base heap and inspecting every memory block. If an error or memory inconsistency is encountered in the underlying base heap, the debug header information, or the overwrite buffers, _CrtCheckMemory generates a debug report with information describing the error condition. When _DEBUG isn't defined, calls to _CrtCheckMemory are removed during preprocessing.

The behavior of _CrtCheckMemory can be controlled by setting the bit fields of the _crtDbgFlag flag using the _CrtSetDbgFlag function. Turning the _CRTDBG_CHECK_ALWAYS_DF bit field ON results in _CrtCheckMemory being called every time a memory allocation operation is requested. Although this method slows down execution, it's useful for catching errors quickly. Turning the _CRTDBG_ALLOC_MEM_DF bit field OFF causes _CrtCheckMemory to not verify the heap and immediately return TRUE.

Because this function returns TRUE or FALSE, it can be passed to one of the _ASSERT macros to create a basic debugging error handling mechanism. The following example causes an assertion failure if corruption is detected in the heap:

_ASSERTE( _CrtCheckMemory( ) );

For more information about how _CrtCheckMemory can be used with other debug functions, see Heap state reporting functions. For an overview of memory management and the debug heap, see CRT debug heap details.

Requirements

Routine Required header
_CrtCheckMemory <crtdbg.h>

For more compatibility information, see Compatibility.

Libraries

Debug versions of C run-time libraries only.

Example

For a sample of how to use _CrtCheckMemory, see crt_dbg1.

See also

Debug routines
_crtDbgFlag
_CrtSetDbgFlag