windows C++内存检测

作为一个C++程序员,一个简单例子更容易理解

#include "stdafx.h"
#include<windows.h>

#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK,__FILE__,__LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif

#define _CRTDBG_MAP_ALLOC
#include <crtdbg.h>
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif

using namespace std;

int _tmain(int argc,char* argv[])
{
 int *p = new int();
 _CrtDumpMemoryLeaks();
 return 0;
}

运行完成后,查看输出窗口。
-->e:\program\test\memleaks\memleaks\memleaks.cpp(23) : {128} client block at 0x0066AF90, subtype 0, 4 bytes long.

这就是我们想要的结果。

posted @ 2014-08-29 11:12  for love@2014  阅读(279)  评论(0编辑  收藏  举报