In my current game project I am worried about memory leaks, and so I want to track objects being created and deleted in the heap.
i figured i could probably do this 2 ways.
The first way: I could use the preprocessor and do a #define on new and delete, overwriting their meanings.
That, however, is hackish and not good.
The better way would be to overload the new and delete operators. I have not, however, overloaded these two specific operators before, although I have overloaded pretty much about ever other operator in C++.
Basically ALL I want to do is have it do the EXACT same thing as the original new/delete keywords, but print out a message that an object is being created or deleted.
Tell me if you think this code would do the trick:
void *operator new ( site_t t )
GloballyDeclaredDebugOutput << "object created...\n";
return malloc( t );
void operator delete ( site_t t )
GloballyDeclaredDebugOutput << "object destroyed...\n";
free( t );