📄 locatememleaks.cpp
字号:
#include "StdAfx.h"
#include "locatememleaks.h"
CLocateMemLeaks * CLocateMemLeaks::pFirstClass ;
volatile LONG CLocateMemLeaks::ulCount;
volatile LONG CLocateMemLeaks::ulActiveCount ;
#ifdef _MULTI_VERSION
CRITICAL_SECTION CLocateMemLeaks::gCsAllocClass;
volatile LONG CLocateMemLeaks::bInit=FALSE ;
#endif
CLocateMemLeaks::CLocateMemLeaks(void)
{
}
CLocateMemLeaks::~CLocateMemLeaks(void)
{
}
CLocateMemLeaks::CLocateMemLeaks(LPTSTR lpszBeginFile, UINT uBeginLine,LPTSTR lpszId)
{
#ifdef _MULTI_VERSION
if(!CLocateMemLeaks::bInit){
::InterlockedIncrement(static_cast<volatile LONG *>(&CLocateMemLeaks::bInit));
::InitializeCriticalSection (&CLocateMemLeaks::gCsAllocClass );
}
ASSERT(CLocateMemLeaks::bInit);
::EnterCriticalSection (&CLocateMemLeaks::gCsAllocClass );
#endif
m_pNextClass=pFirstClass;
pFirstClass=this;
#ifdef _MULTI_VERSION
ASSERT(CLocateMemLeaks::bInit );
::LeaveCriticalSection (&CLocateMemLeaks::gCsAllocClass );
#endif
ASSERT(_tcslen(lpszId));
m_lpszId=CHAR_PTR(new TCHAR[_tcslen(lpszId)*sizeof(TCHAR)+1]);
_tcscpy(m_lpszId.get(),lpszId);
m_lpszBeginFile=CHAR_PTR(new TCHAR[_tcslen(lpszBeginFile)*sizeof(TCHAR)+1]);
TRACE("%d,%d,%d",_tcslen(m_lpszBeginFile.get()),sizeof(TCHAR),_tcslen(lpszBeginFile));
_tcscpy(m_lpszBeginFile.get (),lpszBeginFile);
m_uBeginLine=uBeginLine;
::InterlockedIncrement(static_cast<volatile LONG*>(&CLocateMemLeaks::ulCount) );
::InterlockedIncrement(static_cast<volatile LONG*>(&CLocateMemLeaks::ulActiveCount) );
_CrtMemCheckpoint(&m_msOld);
}
void CLocateMemLeaks::Locate_MemLeaks(LPTSTR lpszEndFile, UINT uEndLine)
{
_CrtMemState msNew,msDif;
_CrtMemCheckpoint(&msNew);
if(_CrtMemDifference(&msDif,&m_msOld,&msNew))
{
TRACE("\n***********************\n");
TRACE("*detected memory leaks!\n");
TRACE("*description:%s\n",m_lpszId.get());
TRACE("*beginning point:\n");
TRACE("%s(%d)\n\n",m_lpszBeginFile.get (),m_uBeginLine);
_CrtMemDumpStatistics(&msDif);
TRACE("\n*ending point:\n");
TRACE("%s(%d)\n",lpszEndFile,uEndLine);
TRACE("************************\n");
ASSERT(CLocateMemLeaks::ulActiveCount );
::InterlockedDecrement(&CLocateMemLeaks::ulActiveCount);
#ifdef _MULTI_VERSION
ASSERT(CLocateMemLeaks::bInit );
::EnterCriticalSection (&CLocateMemLeaks::gCsAllocClass );
#endif
CLocateMemLeaks::pFirstClass =m_pNextClass ;
#ifdef _MULTI_VERSION
ASSERT(CLocateMemLeaks::bInit );
::LeaveCriticalSection (&CLocateMemLeaks::gCsAllocClass );
#endif
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -