#ifdef _DEBUG #define new DEBUG_NEW #endif
来源:互联网 发布:淘宝店铺粉丝专享价 编辑:程序博客网 时间:2024/06/11 16:26
用vs2012的编译器根据向导生成的代码,里面都会出现
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
这个的详细解释是什么呢,查看msdn解释如下:
在寻找内存泄漏的帮助。
在调试模式 (在 _DEBUG 符号定义) 时,DEBUG_NEW 记录其分配的每个对象的文件名和行号。然后,那么,当您使用CMemoryState::DumpAllObjectsSince 成员函数时,每个对象随DEBUG_NEW 显示为分配它的文件名和行号。
使用 DEBUG_NEW,插入以下指令到源文件中:
#define new DEBUG_NEW
一旦插入此指令,预处理器将插入 DEBUG_NEW ,无论在何处使用new和 MFC 执行方式。当您编译程序的发布版本时,DEBUG_NEW 解析为简单的new 操作,并且,文件名和行号信息不生成。在 MFC 的早期版本 (4.1 和早期版本) 需要在调用 IMPLEMENT_DYNCREATE 或 IMPLEMENT_SERIAL 宏的任何语句后放置 #define 语句。 将不再是必需的。
通过上面msdn的解释,大致可以理解那句代码是在调试模式中方便调试的过程时候用到的,在调试过程中,我们本来是通过new分配内存空间的,被 DEBUG_NEW 代替,这个同时传递了除了新开辟的内存区间外,还传递了源文件名和行号,这也是我们在调试过程中,如果一旦内存泄露,能快速的定位到内存泄露的所在行,方便开发人员快速的寻找错误时候用到的,一句话来说就相当于release调试模式下的new的功能,debug模式下寻错定位用的,在实际开发中可以一定程度上缩短寻错的时间
0 0
- #ifdef _DEBUG #define new DEBUG_NEW #endif
- #ifdef _DEBUG #define new DEBUG_NEW #endif的解释
- #ifdef _DEBUG #define new DEBUG_NEW #endif的解释
- #ifdef _DEBUG #define new DEBUG_NEW #endif的解释
- #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE
- #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif 语句解释
- #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif
- #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif
- #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif 语句解释
- #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW...
- #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW...
- #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW...
- #define new DEBUG_NEW
- 关于#define new DEBUG_NEW
- #define new DEBUG_NEW...
- #define new DEBUG_NEW
- #define new DEBUG_NEW
- #define new DEBUG_NEW
- apache 配置文件
- 九章算法面试题17 从输入流中随机取记录
- Android 内存管理机制
- Java web基础总结七之—— Filter与Listener
- GridFS详细分析
- #ifdef _DEBUG #define new DEBUG_NEW #endif
- canvas画布清空问题
- JVM内存模型及垃圾回收机制
- Remove Element ——结题报告
- 安装DSPC
- apache url重写的问题 简化url地址
- CSS 定位 (Positioning)浅析
- 研发管理07:Agile Coach---如何构建敏捷项目管理团队---从自身做起
- DDR3 Write leveling 原理