Я пытаюсь следовать этой статье:
http://flipcode.com/archives/How_To_Find_Memory_Leaks.shtml
для перегрузки моих новых и удаления функций для отслеживания утечек памяти.
однако - если я пытаюсь скомпилировать, я получаю
C2365: «оператор новый»: переопределение; предыдущее определение было «функцией»
в файле xdebug
xdebug включен в xlocale - однако я не могу найти, где мой проект включает xlocale
Я использую MFC для многопоточности в моем проекте.
Может кто-нибудь сказать мне, как я могу заставить мою утечку памяти работать?
// редактировать:
Так что это мой findMemoryLeak.h, который я включаю в конец stdafx.h
#ifndef _FINDMEMORYLEAK_H
#define _FINDMEMORYLEAK_H
#include <list>
using namespace std;
#ifdef _DEBUG
typedef struct {
DWORD address;
DWORD size;
char file[64];
DWORD line;
} ALLOC_INFO;
typedef list<ALLOC_INFO*> AllocList;
AllocList *allocList;
void AddTrack(DWORD addr, DWORD asize, const char *fname, DWORD lnum)
{
ALLOC_INFO *info;
if(!allocList) {
allocList = new(AllocList);
}
info = new(ALLOC_INFO);
info->address = addr;
strncpy(info->file, fname, 63);
info->line = lnum;
info->size = asize;
allocList->insert(allocList->begin(), info);
};
void RemoveTrack(DWORD addr)
{
AllocList::iterator i;
if(!allocList)
return;
for(i = allocList->begin(); i != allocList->end(); i++)
{
if((*i)->address == addr)
{
allocList->remove((*i));
break;
}
}
};
void DumpUnfreed()
{
AllocList::iterator i;
DWORD totalSize = 0;
char buf[1024];
if(!allocList)
return;
for(i = allocList->begin(); i != allocList->end(); i++) {
sprintf(buf, "%-50s:\t\tLINE %d,\t\tADDRESS %d\t%d unfreed\n",
(*i)->file, (*i)->line, (*i)->address, (*i)->size);
OutputDebugString(buf);
totalSize += (*i)->size;
}
sprintf(buf, "-----------------------------------------------------------\n");
OutputDebugString(buf);
sprintf(buf, "Total Unfreed: %d bytes\n", totalSize);
OutputDebugString(buf);
};
inline void * __cdecl operator new(unsigned int size, const char *file, int line)
{
void *ptr = (void *)malloc(size);
AddTrack((DWORD)ptr, size, file, line);
return(ptr);
};
inline void __cdecl operator delete(void *p)
{
RemoveTrack((DWORD)p);
free(p);
};
inline void * __cdecl operator new[](unsigned int size, const char *file, int line)
{
void *ptr = (void *)malloc(size);
AddTrack((DWORD)ptr, size, file, line);
return(ptr);
};
inline void __cdecl operator delete[](void *p)
{
RemoveTrack((DWORD)p);
free(p);
};
#endif
//make the normal new function call the new function with three parameters
#ifdef _DEBUG
#define DEBUG_NEW new(__FILE__, __LINE__)
#else
#define DEBUG_NEW new
#endif
#define new DEBUG_NEW
#endif
когда я включаю его в конец stdafx.h, я получаю тысячи ошибок компиляции, большинство из которых либо в xdebug, либо в xlocale, с первым
C2365: «оператор новый»: переопределение; предыдущее определение было «функцией»
в xdebug по строке 32