Overloading new/delete with additional arguments
For memory management reasons, I'm overloading the operators 'new' and 'delete' in my program. I'd like to know where the memory is allocated and freed, so I add additional parameters. So for example, the 'new' overloaded function takes 3 parameters - size, filename, and line number (the last two passed from the #define in the header file).
These routines handle the memory allocation and freeing themselves, and do things like ensure freed memory is not written to after being freed, mutliple frees, frees of memory not allocated, etc.
However, the problem I have is that my overloaded delete operator is only ever called if there's an exception whilst constructing something within 'new'. I assume the compiler has insufficient knowledge to correctly call the appropriate overloaded 'delete' function, so that leaves me with a few options: I can call another routine to free the memory, or crash the program with the original 'delete' routine (as the memory allocated is not compatible with the original 'delete' command).
Calling another function is fine, and will free all memory associated, but will not call any classes destructor.
So, is there a way to ensure the correct overloaded version of 'delete' is called, or is possible to call a classes destructor, knowing only a pointer to it? (and of course knowing that some 'new' will be allocating more than just classes - for example, char arrays and the like)