36 : freelist_(0), free_start_(0), free_end_(0), chunklist_(0)
38 const size_t alignement = 2 *
sizeof(size_t);
39 size_ = ((size >=
sizeof(block_) ? size :
sizeof(block_))
40 + alignement - 1) & ~(alignement - 1);
48 chunk_* prev = chunklist_->prev;
58 block_* f = freelist_;
70 if (free_start_ + size_ > free_end_)
72 const size_t requested = (size_ > 128 ? size_ : 128) * 8192 - 64;
73 chunk_* c =
reinterpret_cast<chunk_*
>(malloc(requested));
75 throw std::bad_alloc();
79 free_start_ = c->data_ + size_;
80 free_end_ = c->data_ + requested;
83 void* res = free_start_;
98 block_* b =
reinterpret_cast<block_*
>(
const_cast<void*
>(ptr));
105 struct block_ { block_* next; }* freelist_;
109 union chunk_ { chunk_* prev;
char data_[1]; }* chunklist_;
void deallocate(const void *ptr)
Recycle size bytes of memory.
Definition: fixpool.hh:95
fixed_size_pool(size_t size)
Create a pool allocating objects of size bytes.
Definition: fixpool.hh:35
void * allocate()
Allocate size bytes of memory.
Definition: fixpool.hh:56
~fixed_size_pool()
Free any memory allocated by this pool.
Definition: fixpool.hh:44
A fixed-size memory pool implementation.
Definition: fixpool.hh:31