locatememleaks.h

来自「内存定位宏 使用方法: Begin_Locate_Memleaks(ID) En」· C头文件 代码 · 共 61 行

H
61
字号
//LocateMemLeaks.h
#pragma once
#include"crtdbg.h"
#include"stdlib.h"
#include"afxwin.h"
#include"wtypes.h"
#include"afx.h"
#include<memory>
#ifndef _CRTDBG_MAP_ALLOC
  #define _CRTDBG_MAP_ALLOC
#endif
#ifndef _MULTI_VERSION
#define _MULTI_VERSION
#endif
using namespace std;
typedef std::auto_ptr<TCHAR> CHAR_PTR;

class CLocateMemLeaks
{
public:
	CLocateMemLeaks(void);
	~CLocateMemLeaks(void);
	CLocateMemLeaks(LPTSTR lpszBeginFile, UINT uBeginLine,LPTSTR lpszId);
	void Locate_MemLeaks(LPTSTR lpszEndFile, UINT uEndLine);
private:
	CLocateMemLeaks * m_pNextClass;
	_CrtMemState m_msOld;
	CHAR_PTR m_lpszBeginFile;
	CHAR_PTR m_lpszId;
	UINT m_uBeginLine;

public:
	static CLocateMemLeaks * pFirstClass;
	volatile static LONG ulCount;
	volatile static LONG ulActiveCount;
#ifdef _MULTI_VERSION
	static CRITICAL_SECTION gCsAllocClass;
	volatile static LONG  bInit;
#endif
};
//set beginning point for detecting memroy leaks
#ifdef _DEBUG
   #define BEGIN_LOCATE_MEMLEAKS(ID)\
   	  _BEGIN_LOCATE_MEMLEAKS(ID,__FILE__,__LINE__)
#else
   #define BEING_LOCATE_MEMLEAKS() ;
#endif

#define _BEGIN_LOCATE_MEMLEAKS(ID,lpszFile,nLine)\
	static CLocateMemLeaks classname##ID=CLocateMemLeaks(lpszFile,nLine,#ID);

//show the result;
#ifdef _DEBUG
  #define END_LOCATE_MEMLEAKS()\
     _END_LOCATE_MEMLEAKS(__FILE__,__LINE__)
#else
  #define END_LOCATE_MEMLEAKS() ;
#endif

#define _END_LOCATE_MEMLEAKS(lpszFile,nLine)\
CLocateMemLeaks::pFirstClass->Locate_MemLeaks(lpszFile,nLine);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?