文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>检查内存泄露

检查内存泄露

时间:2010-08-20  来源:leiou2009

第二种方法正好是它的补充,Memmory Validator可以检查程序整个运行过程中的内存分配情况,也可以将内存泄漏的位置显示出来

  在实际应用第一种方法时,可以采用两个头文件,用于大型工程的调试,几乎不对其他部分代码产生影响。

//config.h

#define MEMORY_DEBUG

#ifdef MEMORY_DEBUG

#include <stdlib.h>

#include <crtdbg.h>

#endif // MEMORY_DEBUG

------------------------------------------------------------------------------

//debug.h

#ifdef MEMORY_DEBUG

#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)

#define new DEBUG_NEW

#endif // MEMORY_DEBUG

-------------------------------------------------------------------------------

//main.cpp

#include "config.h” // config.h, 第一个头文件

#include "alertparser.h"

#include "alertinfocache.h"

#include <iostream>

#include <pcap.h>

#include "debug.h" //debug.h, 最后一个头文件


int main (int argc, char ** argv)

{


int i = real_main_fun(argc, argv); // 原有的main函数体


if(_CrtDumpMemoryLeaks())

cout<< " memory leak " << endl;

return i;

}

  

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载