static allocator
定义一个allocator来管理内存分配
class allocator
{
public:
void* allocate(size_t);
void deallocate(void*, size_t);
private:
const int CHUNK=5;
struct obj{
struct obj* next;
}
}
void *allocator::allocate(size_t size){
obj* p;
if(!freestore){
freepstore= p= malloc
}
可以定义为宏:
#define DECLARE_POOL_ALLOC()\
public:\
void* operator new(size_t size){}\
void operator delete(){}\
protected:\
static allocator myAlloc;