更新:2007 年 11 月
本主题适用于:
| 版本 | Visual Basic | C# | C++ | Web Developer | 
|---|---|---|---|---|
| 速成版 | .gif) | .gif) | 仅限本机 | .gif) | 
| 标准版 | .gif) | .gif) | 仅限本机 | .gif) | 
| 专业团队版 | .gif) | .gif) | 仅限本机 | .gif) | 
表格图例:
| .gif) | 适用 | 
| .gif) | 不适用 | 
| .gif) | 默认情况下隐藏的一条或多条命令。 | 
在 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 运算符的“Debug”版本可用于所有块类型,并且编译“Release”版本时程序中不需要任何更改。