C++에서 디버그 힙 사용
업데이트: 2007년 11월
이 항목은 다음 언어에 적용됩니다.
Edition |
Visual Basic |
C# |
C++ |
Web Developer |
---|---|---|---|---|
Express |
네이티브 전용 |
|||
Standard |
네이티브 전용 |
|||
Pro 및 Team |
네이티브 전용 |
표의 범례:
해당 |
|
해당 없음 |
|
명령은 기본적으로 숨겨져 있습니다. |
C++에서는 다음 예제와 같이 new 연산자의 디버그 버전을 직접 호출하거나 디버그 모드에서 new 연산자를 대체하는 매크로를 만들 수 있습니다.
new 연산자 대체
/* MyDbgNew.h
Defines global operator new to allocate from
client blocks
*/
#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif // _DEBUG
/* MyApp.cpp
Compile options needed: /Zi /D_DEBUG /MLd
* or use a
* Default Workspace for a Console Application to
* build a Debug version
*/
#include "crtdbg.h"
#include "mydbgnew.h"
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif
int main( ) {
char *p1;
p1 = new char[40];
_CrtMemDumpAllObjectsSince( NULL );
}
delete 연산자의 디버그 버전은 모든 블록 형식에 대해 작동하며, 릴리스 버전을 컴파일할 때 프로그램을 변경할 필요가 없습니다.