AfxCheckMemory
這個函式驗證可用的記憶體集區並視需求列印錯誤訊息。
BOOL AfxCheckMemory( );
傳回值
如果沒有記憶體錯誤則為非零;否則為零。
備註
如果函式未偵測到記憶體損毀,則不會列印。
所有目前配置在堆積上的記憶體區塊已被核取,包括由 new 配置但不是由對基礎記憶體配置器直接呼叫而配置的記憶體區塊,例如 malloc 函式或 GlobalAlloc Windows 函式。 如果找到任何區塊損毀時,訊息會列印到偵錯工具輸出。
如果包含此行:
#define new DEBUG_NEW
在程序模組,對 AfxCheckMemory 的後續呼叫會顯示記憶體配置的檔名和行號。
![]() |
---|
如果您的模組包含可序列化類別的一或多個實作,則您必須在最後一個 IMPLEMENT_SERIAL 巨集呼叫之後加上 #define 這一行。 |
這個函式只在 MFC 偵錯版本中作用。
範例
CAge* pcage = new CAge(21); // CAge is derived from CObject.
Age* page = new Age(22); // Age is NOT derived from CObject.
*(((char*)pcage) - 1) = 99; // Corrupt preceding guard byte
*(((char*)page) - 1) = 99; // Corrupt preceding guard byte
AfxCheckMemory();
需求
標頭: afx.h