关于 DEBUG_NEW
来源:互联网 发布:复杂流程图 软件 编辑:程序博客网 时间:2024/05/17 22:42
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
(1) 在 MFC 中,可以使用 DEBUG_NEW 宏代替 new 运算符来帮助定位内存泄漏。在程序的
“Debug”版本中,DEBUG_NEW将为所分配的每个对象跟踪文件名和行号。当编译程序的
“Release”版本时,DEBUG_NEW 将解析为不包含文件名和行号信息的简单 new 操作。因此,
在程序的“Release”版本中不会造成任何速度损失。
如果不想重写整个程序来使用 DEBUG_NEW代替new,则可以在源文件中定义下面的宏:
#define new DEBUG_NEW 当进行对象转储时,用 DEBUG_NEW分配的每个对象均将显示被分配
#define new DEBUG_NEW 当进行对象转储时,用 DEBUG_NEW分配的每个对象均将显示被分配
到的文件和行号,使您可以查明内存泄漏源。
MFC 框架的“Debug”版本自动使用 DEBUG_NEW,但代码不自动使用它。如果希望利用 DEBUG_NEW 的好处,则必须显式使用 DEBUG_NEW 或 #define new DEBUG_NEW,如上所示。
MFC 框架的“Debug”版本自动使用 DEBUG_NEW,但代码不自动使用它。如果希望利用 DEBUG_NEW 的好处,则必须显式使用 DEBUG_NEW 或 #define new DEBUG_NEW,如上所示。
(2)__FILE__和__LINE__都是编译器定义的宏。当碰到__FILE__时,编译器会把__FILE__替换成一个字符串,这个字符串就是当前在编译的文件的路径名。在DEBUG_NEW的定义中没有直接使用__FILE__,而是用了THIS_FILE,其目的是为了减小目标文件的大小。假设在某个cpp文件中有100处使用了new,如果直接使用__FILE__,那编译器会产生100个常量字符串,这100个字符串都是这个cpp文件的路径名,显然十分冗余。如果使用THIS_FILE,编译器只会产生一个常量字符串,那100处new的调用使用的都是指向常量字符串的指针。
(3) 这是dubug时输出出错在文件文件位置信息的一些宏.
THIS_FILE
Remarks
The information is used by the ASSERT and VERIFY macros. The Application Wizard and code wizards place the macro in source code files they create.
Example
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// __FILE__ is one of the six predefined ANSI C macros that the compiler recognizes.
THIS_FILE
Remarks
The information is used by the ASSERT and VERIFY macros. The Application Wizard and code wizards place the macro in source code files they create.
Example
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// __FILE__ is one of the six predefined ANSI C macros that the compiler recognizes.
另外:
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
这两个函数是调试用的,第一个函数检查可用性,即是否有效。第二个函数如果未更改的话,
这两个函数是调试用的,第一个函数检查可用性,即是否有效。第二个函数如果未更改的话,
最终调用的是Cwnd::Dump(); 输出窗口类名,标题名等一系列信息(在输出窗口中)
- 关于 DEBUG_NEW
- 关于 DEBUG_NEW
- 关于#define new DEBUG_NEW
- 关于#define new DEBUG_NEW
- 关于"#define new DEBUG_NEW"
- DEBUG_NEW
- DEBUG_NEW
- debug_new
- DEBUG_NEW
- DEBUG_NEW
- DEBUG_NEW,_DEBUG
- 关于C++中常用的对DEBUG_NEW、THIS_FILE重定义的说明
- #define new DEBUG_NEW
- #define new DEBUG_NEW...
- #define new DEBUG_NEW
- new和DEBUG_NEW
- #define new DEBUG_NEW
- #define new DEBUG_NEW
- vc中关于 directx的配置,和dxsdk_extras(directshow)
- A. Array
- A Fault Model and Mutation Testing of Access Control Policies
- jboss端口说明
- OpenCV写入的视频
- 关于 DEBUG_NEW
- 解像度
- Verification and Change-Impact Analysis of Access Control Policies
- android 反编译
- 在Linux下安装android开发环境并以USB调试方式链接手机进行开发
- 2013-5-1
- Testing security policies: going beyond functional testing
- 文件系统 btrfs
- qemu 学习(一)————qemu整体流程解读