36 : freelist_(nullptr), free_start_(nullptr),
37 free_end_(nullptr), chunklist_(nullptr)
39 const size_t alignement = 2 *
sizeof(size_t);
40 size_ = ((size >=
sizeof(block_) ? size :
sizeof(block_))
41 + alignement - 1) & ~(alignement - 1);
49 chunk_* prev = chunklist_->prev;
59 block_* f = freelist_;
71 if (free_start_ + size_ > free_end_)
73 const size_t requested = (size_ > 128 ? size_ : 128) * 8192 - 64;
74 chunk_* c =
reinterpret_cast<chunk_*
>(malloc(requested));
76 throw std::bad_alloc();
80 free_start_ = c->data_ + size_;
81 free_end_ = c->data_ + requested;
84 void* res = free_start_;
99 block_* b =
reinterpret_cast<block_*
>(
const_cast<void*
>(ptr));
106 struct block_ { block_* next; }* freelist_;
110 union chunk_ { chunk_* prev;
char data_[1]; }* chunklist_;
void deallocate(const void *ptr)
Recycle size bytes of memory.
Definition: fixpool.hh:96
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:57
~fixed_size_pool()
Free any memory allocated by this pool.
Definition: fixpool.hh:45
A fixed-size memory pool implementation.
Definition: fixpool.hh:31