c++ - overloading new and delete -
I try to follow this article:
To track the memory of your new And surcharge the overloaded work leak.
However - if I try to compile, I get a
C335: "operator new": redefinition; The previous description was done in a "function"
file xdebug
xdebug becomes in xlocale - however, i can not find where including my project xlocale
I am using MFC for multithreading in my project.
Can someone tell me how my memory leakage tracking can be done to work?
// Edit: So this is my search lecture mole which I included at the end of stdafx.h
#ifndef _FINDMEMORYLEAK_H #define _FINDMEMORYLEAK_H # include & lt ; List & gt; using namespace std; #ifdef _DEBUG typedef struct {DWORD address; DWORD size; Four files [64]; DWORD line; } ALLOC_INFO; Typefiff list & lt; ALLOC_INFO * & gt; AllocList; Olocaust * Aloclist; Zero AddTrack (DWORD addr, DWORD asize, const char * fname, DWORD lnum) {ALLOC_INFO * info; If (! Illustrations) {allocList = new (global); } Info = new (ALLOC_INFO); Info- & gt; Address = addr; Strncpy (info-> files, fname, 63); Info- & gt; Line = lnum; Info- & gt; Size = asize; AllocList- & gt; Insert (Alcoholist-> Start (), info); }; Zero RemoveTrack (DWORD addr) {AllocList :: iterator i; If (! Aloclist) return; (I = allocList- & gt; start (); i = allocList-> end (); i ++!) {If ((* i) -> address == addr) {allocList- & gt; Can remove ((* i)); break; }}}; Zero DumpUnfreed () {AllocList :: iterator i; DWORD totalSize = 0; Four buff [1024]; If (! Aloclist) return; (I = allocList- & gt; start (); i = allocList-> end (); i ++!) {Sprintf (buf, "% -50s: \ t \ tLINE% d, \ t \ tADDRESS% D \ t% d false \ n ", (* i) -> file, (* i) -> gt; line, (* i) - & gt; address, (* i) - & gt; shape) ; OutputDebugString (buf); TotalSize + = (* i) - & gt; Shape; } Sprintf (buf, "-------------------------------------------- --------------- \ n "); OutputDebugString (buf); Sprintf (Buff, "Total Unpublished:% d bytes \ n", Total Size); OutputDebugString (buf); }; Inline Zero * __cdecl operator new (unsigned full size, const char * file, int row) {zero * ptr = (zero *) malloc (size); AddTrack (DWORD) PTR, size, file, line); Return (PTR); }; Inline Zero __cdecl Operator Removal (Zero * P) {RemoveTrack (DWORD) P); Free (P); }; Inline Zero * __cdecl operator new [] (unsigned full size, const char * file, int row) {zero * ptr = (zero *) malloc (size); AddTrack (DWORD) PTR, size, file, line); Return (PTR); }; Delete Inline Zero __cdecl operator [] (Zero * P) {RemoveTrack (DWORD) P); Free (P); }; #endif // Creating a new task with three criteria #ifdef _DEBUG #define DEBUG_NEW new (__ FILE__, __LINE__) #else #define DEBUG_NEW new #endif #define new DEBUG_NEW #endif
When I include this in the end of stdafx.h, I get thousands of compilererrors most of them either in xdebug or xlocale, being already with
with C2365 : "Operator new": Definition;
I have solved, the previous definition was a "function"
in xdebug Line 32 a while ago
What is happening is that the word you receive on your surcharge, the word of new
is a macro (given, it is our Linking problems did not resolve), but try adding:
#undef new
Finally, after the Directorate in your file, first Before the newer
overload
Edit
This is because, in some CPP file, stdafx.h
(or something else) before including your memory leak detection code DEBUG_NEW defines a file that is included) (you should be able to find out which compiler errors). Thus new
is defined as a macro which is caused by Barf on the definition of your compiler.
Comments
Post a Comment