For a general C ++ memory tracker, you need to overload the following:
global operator new global operator new [] global operator delete global operator delete [] any class allocators any in-place allocators
A complex bit receives useful information, overloaded operators have only size information for allocators and memory pointers for deletion. One answer is to use macros. I know. Nastya. An example is a place in the header that is included from all source files:
#undef new void *operator new (size_t size, char *file, int line, char *function);
and create the source file with:
void *operator new (size_t size, char *file, int line, char *function) {
The above only works if you do not have an operator defined in the class. If you have some in the scope of the class, follow these steps:
#define NEW new (__FILE__, __LINE__, __FUNCTION__)
and replace "new type" with "NEW type", but this requires a lot of code to be changed.
As a macro, deleting a memory tracker is quite simple, the title becomes:
#if defined ENABLED_MEMORY_TRACKER #undef new void *operator new (size_t size, char *file, int line, char *function); // other operators #define NEW new (__FILE__, __LINE__, __FUNCTION__) #else #define NEW new #endif
and implementation file:
#if defined ENABLED_MEMORY_TRACKER void *operator new (size_t size, char *file, int line, char *function) {