How to overload operator new/delete to implement a fast allocator?
1, I already have a fast allocator like this:
struct FastAllocator
{
FastAllocator(size_t fixed_size);
void* Allocate(size_t size);
void Free(void* ptr);
};
2, I also have a class A that is required to be dynamically
allocated/deleted quickly. So I think of overloading operator new and
operator delete inside class A's definition like this:
struct A
{
int buf[1024];
void* operator new(size_t size);
void operator delete(void* ptr);
};
3, Because operator new and operator delete are both static methods, thus,
I cannot access the this pointer.
4, My question is: How should I initialize the FastAllocator's instance
that can be accessed by operator new and operator delete?
No comments:
Post a Comment