VC++中 #undef THIS_FILE意思

VC++中


MSDN中:

Remarks

    Assists in finding memory leaks. You can use DEBUG_NEW everywhere in your program that you would ordinarily use the new operator to allocate heap storage.

    In debug mode (when the _DEBUG symbol is defined), DEBUG_NEW keeps track of the filename and line number for each object that it allocates. Then, when you use the CMemoryState::DumpAllObjectsSince member function, each object allocated with DEBUG_NEW is shown with the filename and line number where it was allocated.

To use DEBUG_NEW, insert the following directive into your source files:

#define new DEBUG_NEW

    Once you insert this directive, the preprocessor will insert DEBUG_NEW wherever you use new, and MFC does the rest. When you compile a release version of your program, DEBUG_NEW resolves to a simple new operation, and the filename and line number information is not generated.

 备注
帮助发现内存泄漏。你可以在程序中的任何地方使用DEBUG_NEW,通常使用新的操作符来分配堆存储。
在调试模式下(当定义了_DEBUG符号时),DEBUG_NEW跟踪它分配的每个对象的文件名和行号。然后,当您使用CMemoryState :: DumpAllObjectsSince成员函数时,分配有DEBUG_NEW的每个对象都显示为分配了它的文件名和行号。
要使用DEBUG_NEW,请将以下指令插入到源文件中:
#define new DEBUG_NEW
一旦你插入这个指令,预处理器将插入DEBUG_NEW,无论你使用new,而MFC做剩下的。当编译您的程序的发行版本时,DEBUG_NEW将解析为一个简单的新操作,并且不会生成文件名和行号信息。



    意思是,当在debug模式下时,我们分配内存时的new被替换成DEBUG_NEW,而这个DEBUG_NEW不仅要传入内存块的大小,还要传入源文件名和行号,这样,当发生内存泄漏时,我们可以在调试模式下定位到该问题代码处。若删掉该句,就不能进行定位了。而在release版本下的new就是简单的new,并不会传入文件名和行号。
    如果定义了_DEBUG,表示在调试状态下编译,因此相应修改了两个符号的定义THIS_FILE是一个char数组全局变量,字符串值为当前文件的全路径,这样在Debug版本中当程序出错时出错处理代码可用这个变量告诉你是哪个文件中的代码有问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值