#ifdef _DEBUG virtual void AssertValid() const; //assert(断言)valid(有效的,正确的) virtual void Dump(CDumpContext& dc) const; //存储上下文 #endif 这两个函数是调试用的,第一个函数检查可用性,即是否有效 第二个函数如果未更改的话,最终调用的是Cwnd::Dump(); 输出窗口类名,标题名等一系列信息(在输出窗口中) #ifdef _DEBUG #endif 这是条件编译,即如果有#define _DEBUG这两个函数会编译,否则忽略, 当你用debug生成时(相对于release)开发环境则自动的加上这个宏定义,这两个函数有效。

2 #ifdef   _DEBUG     //   判断是否定义_DEBUG   #undef   THIS_FILE     //   取消THIS_FILE的定义   static   char   THIS_FILE[]=__FILE__;     //   定义THIS_FILE指向文件名   #define new    DEBUG_NEW     //   定义调试new宏,取代new关键字   #endif     //   结束       如果定义了_DEBUG,表示在调试状态下编译,因此相应修改了两个符号的定义 THIS_FILE是一个char数组全局变量,字符串值为当前文件的全路径,这样在Debug版本中当程序出错时出错处理代码可用这个变量告诉你是哪个文件中的代码有问题。 定义 _DEBUG后,由于定义了_DEBUG,编译器确定这是一个调试,编译#ifdef   _DEBUG和#endif之间的代码。#undef   表示清除当前定义的宏,使得THIS_FILE无定义。__FILE__   是编译器能识别的事先定义的ANSI   C   的6个宏之一。#define   new   DEBUG_NEW   DEBUG_NEW定位内存泄露并且跟踪文件名. //////////////////////////////////////////////////////////////////////// ///另一种解释 #ifdef     _DEBUG     //如果是debug状态   #undef     THIS_FILE     //清除THIS_FILE   static     char     THIS_FILE[]=__FILE__;     //定义THIS_FILE为                                        //__FILE__(这是当前文件全路径名字)       #define    new     DEBUG_NEW     //定义new为DEBUG_NEW(这个可以检测到内存泄露之类的问题,其实就是可以使用crt开头的那几个调试函数)   #endif

在用vc时,利用AppWizard会产生如下代码:

#ifdef _DEBUG  #define new DEBUG_NEW  #undef THIS_FILE  static char THIS_FILE[] = __FILE__;  #endif

对于

#define new DEBUG_NEW 首先看msdn的解释:

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.

再查看定义:

#ifdef _DEBUG

void* AFX_CDECL operator new(size_t nSize, LPCSTR lpszFileName, int nLine);           #define DEBUG_NEW new(THIS_FILE, __LINE__)

#else

#define DEBUG_NEW new

#endif

最新文章

  1. Java进击C#——语法之IO操作
  2. 20160622001 GridView 删除列 用模板实现删除时提示确认框
  3. 解决TalbleView头部或底部子控件不显示问题
  4. ABAP-SQL基础知识
  5. Second Level Cache for Entity Framework 6.1
  6. 【转】高性能Javascript--脚本的无阻塞加载策略
  7. 128. Longest Consecutive Sequence
  8. ubuntu14.04安装MATLAB R2014a
  9. Linux系统下如何修改主机名
  10. JavaScript高级程序设计:第十七章
  11. Python的自学之路:Python基础(一)
  12. Django的CBV和FBV
  13. C语言第五次博客作业--函数
  14. React 关于组件(界面)更新
  15. 基于promtheus的监控解决方案
  16. xpath路径定位
  17. PHP防CC攻击代码
  18. Kali学习笔记5:被动信息收集工具集
  19. 8 -- 深入使用Spring -- 3... 资源访问
  20. 在T-SQL语句中访问远程数据库

热门文章

  1. C# 在Visual Studio中一个项目有两个Main函数, 怎么设置哪个是入口?取代csc /main选项。
  2. sql where 1=1
  3. 1029 C语言文法
  4. 09---Net基础加强
  5. sql 表连接 join
  6. MySQL的基本函数
  7. PHP生成二维码【谷歌API+qrcode+圆角Logo】
  8. 三层架构和MVC模式
  9. NOIP201302表达式求值
  10. yum安装mysql后没有mysqld