J
Jay Nabonne
Hi,
This might sound odd, but we want to replace the allocation scheme used by
new and delete without changing operator new and operator delete. (The
global operators are shared and we can't change them.)
We can replace operator new functionality by providing additional
parameters to the new function call (ala Stroustrup):
class foo_t;
extern foo_t foo;
void * operator new(size_t size, const foo_t&) { return malloc(size); }
void operator delete(void * p, const foo_t&) { free(p); }
char* p = new(foo) char;
But you can't do that with operator delete. There's no way to invoke the
parametrized delete operator, short of calling "operator delete(p, foo)"
which won't invoke destructors (it just calls the memory deallocator).
So, is there a way to replace delete functionality without overriding the
global delete operator?
- Jay
This might sound odd, but we want to replace the allocation scheme used by
new and delete without changing operator new and operator delete. (The
global operators are shared and we can't change them.)
We can replace operator new functionality by providing additional
parameters to the new function call (ala Stroustrup):
class foo_t;
extern foo_t foo;
void * operator new(size_t size, const foo_t&) { return malloc(size); }
void operator delete(void * p, const foo_t&) { free(p); }
char* p = new(foo) char;
But you can't do that with operator delete. There's no way to invoke the
parametrized delete operator, short of calling "operator delete(p, foo)"
which won't invoke destructors (it just calls the memory deallocator).
So, is there a way to replace delete functionality without overriding the
global delete operator?
- Jay