_CrtCheckMemory

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

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 is not 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 is 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 simple 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 Memory Management and the Debug Heap.

Requirements

Routine

Required header

_CrtCheckMemory

<crtdbg.h>

For more compatibility information, see Compatibility in the Introduction.

Libraries

Debug versions of C run-time libraries only.

Example

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

.NET Framework Equivalent

System::Diagnostics::PerformanceCounter

See Also

Concepts

Debug Routines

_crtDbgFlag

_CrtSetDbgFlag