Export (0) Print
Expand All

Debug Heap Features 

This topic applies to:

Visual Studio Edition

Visual Basic

C#

C++

J#

Express

No

No

Native

No

Standard

No

No

Native

No

Pro/Team

No

No

Native

No

Many of the debug heap's features must be accessed from within your code. The following section describes some of the features and how to use them.

_CrtCheckMemory

You can use a call to _CrtCheckMemory, for example, to check the heap's integrity at any point. This function inspects every memory block in the heap, verifies that the memory block header information is valid, and confirms that the buffers have not been modified.

_CrtSetDbgFlag

You can control how the debug heap keeps track of allocations using an internal flag, _crtDbgFlag, which can be read and set using the _CrtSetDbgFlag function. By changing this flag, you can instruct the debug heap to check for memory leaks when the program exits and report any leaks that are detected. Similarly, you can specify that freed memory blocks not be removed from the linked list, to simulate low-memory situations. When the heap is checked, these freed blocks are inspected in their entirety to ensure that they have not been disturbed.

The _crtDbgFlag flag contains the following bit fields:

Bit field Default value Description

_CRTDBG_ALLOC_MEM_DF

On

Turns on debug allocation. When this bit is off, allocations remain chained together but their block type is _IGNORE_BLOCK.

_CRTDBG_DELAY_FREE_MEM_DF

Off

Prevents memory from actually being freed, as for simulating low-memory conditions. When this bit is on, freed blocks are kept in the debug heap's linked list but are marked as _FREE_BLOCK and filled with a special byte value.

_CRTDBG_CHECK_ALWAYS_DF

Off

Causes _CrtCheckMemory to be called at every allocation and deallocation. This slows execution, but catches errors quickly.

_CRTDBG_CHECK_CRT_DF

Off

Causes blocks marked as type _CRT_BLOCK to be included in leak-detection and state-difference operations. When this bit is off, the memory used internally by the run-time library is ignored during such operations.

_CRTDBG_LEAK_CHECK_DF

Off

Causes leak checking to be performed at program exit via a call to _CrtDumpMemoryLeaks. An error report is generated if the application has failed to free all the memory that it allocated.

See Also

Community Additions

ADD
Show:
© 2014 Microsoft