I would like to wrap the global operators new() and delete().  I am able to
do this using global overrides:
void * operator new   ( UInt32 s ) { return _DbgNew(s); }
void operator delete(void* p)    { return _DbgFree(p); }

Using these wrappers, can anyone think of a method by which I'm able to
track, at a minimum, the name of the class being allocated?  The idea is
when my app shuts down, I run through my list of allocations and if any
exist, I say "You leaked a class object of type %s in file %s line %d".  I
am able to do this with MemHandleNew and friends by wrapping them in a macro
and taking advantage of the ANSI macros  __FILE__ and __LINE__.  For
example:

// Wrap MemHandleNew to a function that records the location of allocation:
 #define MemHandleNew(x) _DbgMemHandleNew( x, __FILE__, __LINE__ )

Unfortunately, this macro approach doesn't work with operator new(), and
trapping sysTrapMemPtrNew doesn't afford me useful values for __FILE__ and
__LINE__.

The only thing I can think of is developing a root class 'Object' from which
all other classes derive, with a pure virtual initialization method that
defines a constant string that contains the derived class name.  This method
would attempt to find its 'this' pointer in my accumulated list of
allocations, and on success, inject its name string into the allocation
record.

Too bad I can't just call someObject.getClass().getName()!

Thanks for your help!
-Jeff Ishaq





-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to