欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
#ifdef

1
#ifdef _DEBUG
virtual void AssertValid() const; //assert(
斷言)valid(有效的,正確的
)
virtual void Dump(CDumpContext& dc) const; //
存儲上下文

#endif
這兩個(gè)函數是調試用的,第一個(gè)函數檢查可用性,即是否有效
第二個(gè)函數如果未更改的話(huà),最終調用的是
Cwnd::Dump();
輸出窗口類(lèi)名,標題名等一系列信息(在輸出窗口中)

#ifdef _DEBUG
#endif
這是條件編譯,即如果有#define _DEBUG這兩個(gè)函數會(huì )編譯,否則忽略,

當你用debug生成時(shí)(相對于release)開(kāi)發(fā)環(huán)境則自動(dòng)的加上這個(gè)宏定義,這兩個(gè)函數有效。

2
#ifdef   _DEBUG     //
判斷是否定義
_DEBUG  
#undef   THIS_FILE     //
取消THIS_FILE的定義
  
static   char   THIS_FILE[]=__FILE__;   //
定義THIS_FILE指向文件名
  
#define new    DEBUG_NEW     //
定義調試new宏,取代new關(guān)鍵字
  
#endif     //
結束
      
如果定義了_DEBUG,表示在調試狀態(tài)下編譯,因此相應修改了兩個(gè)符號的定義

THIS_FILE
是一個(gè)char數組全局變量,字符串值為當前文件的全路徑,這樣在Debug版本中當程序出錯時(shí)出錯處理代碼可用這個(gè)變量告訴你是哪個(gè)文件中的代碼有問(wèn)題。
定義 _DEBUG后,由于定義了_DEBUG,編譯器確定這是一個(gè)調試,編譯#ifdef   _DEBUG#endif之間的代碼。#undef   表示清除當前定義的宏,使得THIS_FILE無(wú)定義。__FILE__   是編譯器能識別的事先定義的ANSI   C   6個(gè)宏之一。#define   new   DEBUG_NEW  
DEBUG_NEW
定位內存泄露并且跟蹤文件名
.
////////////////////////////////////////////////////////////////////////
///
另一種解釋

#ifdef     _DEBUG     //
如果是debug狀態(tài)  
#undef     THIS_FILE     //
清除
THIS_FILE  
static     char     THIS_FILE[]=__FILE__;     //
定義THIS_FILE                                        //__FILE__(這是當前文件全路徑名字)
      
#define    new     DEBUG_NEW     //
定義newDEBUG_NEW(這個(gè)可以檢測到內          //存泄露之類(lèi)的問(wèn)題,其實(shí)就是可以使用crt開(kāi)頭的那幾個(gè)調試函數)
  
#endif

在用vc時(shí),利用AppWizard會(huì )產(chǎn)生如下代碼:

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

對于

#define new DEBUG_NEW
首先看msdn的解釋?zhuān)?span lang="EN-US">

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

這樣就很清楚了,當在debug模式下時(shí),我們分配內存時(shí)的new被替換成DEBUG_NEW,而這個(gè)DEBUG_NEW不僅要傳入內存塊的大小,還要傳入源文件名和行號,這就有個(gè)好處,即當發(fā)生內存泄漏時(shí),我們可以在調試模式下定位到該問(wèn)題代碼處。若刪掉該句,就不能進(jìn)行定位了。而在release版本下的new就是簡(jiǎn)單的new,并不會(huì )傳入文件名和行號。

因此,我們在開(kāi)發(fā)代碼階段,保留上述代碼是值得的。

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
 #define new DEBUG
用宏構建自己的printf函數
Linux下syslog日志函數使用
宏總結
編譯預處理指令【精】
extern
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久