[comp.lang.c++] memory allocation watching

bby@palladium.UUCP (Bob Mastors) (06/09/89)

If you have wrapper routines around malloc/realloc/free, like I do,
and like to pass in __LINE__ and __FILE__ to see what part of the program
is messing up, then you may have been wondering how to pass __LINE__
and __FILE__ to your wrapper routines when new and delete is called.

A solution is to put the following in an include file and change all
of your "new" references to "tnew":
    extern int curline;
    extern char *curfile;
    #define tnew (!((curline = __LINE__), (curfile = __FILE__))) ? 0 : new
If you have a cpp that is trying to conform to the ANSI C draft
then you can call it new instead of tnew and you won't get recursion on
the macro.

You will need your own version of _new that passes curfile and curline
to your wrapper routine that calls malloc.  And of course you will
want to duplicate all this for the delete operator.

---
Bob Mastors
Epoch Systems, Marlboro MA (508) 481-3717
{linus!alliant, harvard!cfisun}!palladium!bby
-- 
---
Bob Mastors
Epoch Systems, Marlboro MA (508) 481-3717
{linus!alliant, harvard!cfisun}!palladium!bby