Re: Possible to access standard global new operator after it's been
overridden?
* Billy:
Is it possible to access the standard global new operator after it's been
overridden?
It's generally not a good idea to override the global new operators.
Many library functions assume very specific behavior from the global new
operators, and they are also customization points for applications that
handle out-of-memory conditions.
Instead, you can override per class.
For instance, I have a situation like this
void* operator new( size_t numBytes )
{
return sDefaultHeap->Allocate( numBytes );
}
Heap::Heap( unsigned int memSize )
{
// allocate memory for the heap
m_memory = new char[ memSize ];
}
void InitDefaultHeap( void )
{
// this function doesn't currently work because new has been
// overridden :(
char* defaultMem = new char[1024];
sDefaultHeap( defaultMem, 1024 );
}
I guess it's possible that sDefaultHeap is defined like this:
struct DefaultHeap
{
struct Foo
{
void* Allocate( size_t ) { ... }
};
Foo bar;
Foo* operator->() { return &bar; }
void operator()( char* p, int i ) { ... }
};
DefaultHeap sDefaultHeap;
but more likely I think the code you have presented is just some fantasy
code.
Please read the FAQ item on how to get help with code that doesn't work,
in particular, how to present such code.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?