共用方式為


C++ 的偵錯堆積

更新:2007 年 11 月

這個主題適用於:

版本

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 運算子的偵錯版本會作用在所有的區塊類型上,當您編譯發行版本時不需要在程式裡做任何的變更。

請參閱

其他資源

CRT 偵錯堆積