22 #include <spot/misc/common.hh> 23 #include <spot/misc/hash.hh> 34 static const size_t alignment_ = 2 *
sizeof(size_t) - 1;
38 : free_start_(nullptr), free_end_(nullptr), chunklist_(nullptr)
47 chunk_* prev = chunklist_->prev;
53 size_t fixsize(
size_t size)
const 55 if (size <
sizeof(block_))
56 size =
sizeof(block_);
58 return (size + alignment_ - 1) & ~(alignment_ - 1);
67 block_*& f = freelist_[size];
80 if (free_start_ + size > free_end_)
82 const size_t requested = (size > 128 ? size : 128) * 8192 - 64;
83 chunk_* c =
reinterpret_cast<chunk_*
>(malloc(requested));
85 throw std::bad_alloc();
89 free_start_ = c->data_ + size;
90 free_end_ = c->data_ + requested;
93 void* res = free_start_;
111 size = fixsize(size);
112 block_* b =
reinterpret_cast<block_*
>(
const_cast<void*
>(ptr));
113 block_*& f = freelist_[size];
119 struct block_ { block_* next; };
120 std::unordered_map<size_t, block_*> freelist_;
124 union chunk_ { chunk_* prev;
char data_[1]; }* chunklist_;
Definition: automata.hh:26
multiple_size_pool()
Create a pool.
Definition: mspool.hh:37
void deallocate(const void *ptr, size_t size)
Recycle size bytes of memory.
Definition: mspool.hh:108
~multiple_size_pool()
Free any memory allocated by this pool.
Definition: mspool.hh:43
A multiple-size memory pool implementation.
Definition: mspool.hh:32
void * allocate(size_t size)
Allocate size bytes of memory.
Definition: mspool.hh:63