hello.
suppose,we have hierarchy of classes and we want to make them allocate/deallocate theirs memory only throughout our memory manager. what is a classical C++ way to achieve this behavior? is it a MUST* to have additional checks such as:
class Foo{
public:
virtual ~Foo(){}
void* operator new(size_t bytes)
{
if (bytes != sizeof(Foo)){
return ::operator new(bytes);
}
return g_memory_manager.alloc(bytes);
}
void operator delete(void *space, size_t bytes)
{
if (bytes != sizeof(Foo)){
return ::operator delete(space);
}
g_memory_manager.dealloc(space, bytes);
}
}
thanks for help.