Stop calling overloaded operator new and delete by stl containers

I am developing a memoryleak tool. In this, I overload the new and deleting operator. His work is wonderful. But the code for which I am creating this tool is about 15,000 lines. I can’t modify the existing code, I can call the memoryleak tool function in the existing code. Existing code with stl containers (e.g. list, map, stack, etc.). The Stl container also calls the new and delete statements to allocate or free memory. I want the stl container to call the new and delete operator, which was not overloaded with the new one and deleted it. for ex:

int *iptr = new int[10] ----> should call overloaded new[]
delete [] iptr -------------> should call overloaded delete[]
map.insert(10) -------------> should call default new[] ( which are in new.h)
map.erase()  ---------------> should call default delete[] ( which are in new.h)

How can i do this? Any help would be appreciated.

Sorry to forget to mention that I am replacing a new one and deleting using the following macros:

#define new DEBUG_NEW
#define DEBUG_NEW TrackMemory(__FILE__, __LINE__) ->* new
#define delete TrackDelete(__FILE__, __LINE__); delete

TrackMemory , . , stl- , , . ,

+3
3

15000 ? , new delete - ( __FILE__ __LINE__ ), .

, valgrind.

+2

"" . :

void *operator new (size_t memorySize);
void *operator new[] (size_t memorySize);
void *operator new (size_t memorySize, const std::nothrow_t &) throw ();
void *operator new[] (size_t memorySize, const std::nothrow_t &) throw ();
void operator delete (void *memoryPointer);
void operator delete[] (void *memoryPointer);
void operator delete (void *memoryPointer, const std::nothrow_t &) throw ();
void operator delete[] (void *memoryPointer, const std::nothrow_t &) throw ();

:

void *myNew (size-t memorySize);
void myDelete (void *memoryPointer);

myNew myDelete , .

myNew myDelete HeapAlloc HeapFree.

( Visual Studio):

#pragma init_seg(lib)

.

. , myNew.

, .

, StackWalk, , .

, , , :

  • , Visual Studio . , , .
  • #define new, delete, alloc,..., (, , (. Qt), , .lib, ( Qt)).
  • , . ( , ,...).

, , (, , , , , , ,...).

+2

, , , new. , . , , , - . . ( ).

- new, , , new , , , .

0

Source: https://habr.com/ru/post/1790940/


All Articles