Additional parameters for operator delete
I want to keep track of memory deletions and alloctions with the standard c++ operators. I wrote an include that define a new and delete macro that add a few parameters to those already specified in the sourcecode as well as the overloaded operators to handle these additional parameters. Basically the idea is that I don't want to change any source code for the debug build, except for an additional #include.
The additional parameters for a debug build are: current line in code and the sourcefile name. Well, I guess that was obvious ;)
I have defined a new macro that replaces something like pImg= new CImage; with pImg= new(__LINE__, __FILE) CImage;. I think that's how most people do it. At least that's what somebody suggested on the net. So far, this works very well.
However, I ran into complications while trying to do this with delete: It seems something like delete(__LINE__, __FILE__) pImg; is not valid C++ code and I don't think it's possible to write a macro that turns delete pImg; into delete(pImg, __LINE__, __FILE__);
Since this seems to be a more or less common problem I hope that maybe somebody else already found a sollution to this problem. I have been trying quite a lot of things (i.e. to write a macro that splits the deletion into two statements like _setDelete(__LINE__, __FILE); delete pImg;, but that might cause trouble if it's used in an if-statement without curly brackets etc.. It's also extremely ugly code (reason enough not to use it) ;) ).
Any suggestions are welcome - if you don't know what I'm talking about, please ask. This isn't my native language, but it's supposed to be English...