> From: Jeff Ishaq [mailto:[EMAIL PROTECTED]]
> // 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()
Actually you _can_ do that with operator new. The trick is to use the
'placement new' form, which is the variant where you can pass extra
arbitrary parameters to operator new. Something like this:
#if DEBUG_MEMORY_ALLOCATIONS
# define NEW new( __FILE__, __LINE__ )
#else
# define NEW new
#endif
void * operator new( UInt32 size, const char *file, int line )
{
// ... implement allocation with file/line logging ...
}
void operator delete( void *p )
{
// ... implement deallocation ...
}
Given those definitions, in your code you just change 'new' (lower case C++
keyword) to 'NEW' (upper case macro) like this:
FooClass *pFoo = NEW FooClass;
which the preprocessor expands out to this (in debug mode):
FooClass *pFoo = new( __FILE__, __LINE__ ) FooClass;
which passes the file name and line number, as desired.
(And if you are new'ing arrays in addition to single objects, make sure to
override 'operator new []' and 'operator delete []' too.)
-slj-
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/