22 #include <spot/misc/common.hh>
23 #include <spot/misc/clz.hh>
25 #if SPOT_DEBUG && defined(HAVE_VALGRIND_MEMCHECK_H)
26 #include <valgrind/memcheck.h>
43 template<pool_type Kind>
54 if (size <
sizeof(block_))
55 size =
sizeof(block_);
57 if (!(size & (size-1)))
60 else if (size <
alignof(std::max_align_t))
61 return size_t{1} << (CHAR_BIT*
sizeof(size_t) - clz(size));
64 size_t mask =
alignof(std::max_align_t)-1;
65 return (size + mask) & ~mask;
79 chunk_* prev = chunklist_->prev;
80 ::operator
delete(chunklist_);
89 block_* f = freelist_;
93 #if SPOT_DEBUG && defined(HAVE_VALGRIND_MEMCHECK_H)
94 if (Kind == pool_type::Safe)
96 VALGRIND_MALLOCLIKE_BLOCK(f, size_, 0,
false);
99 VALGRIND_MAKE_MEM_DEFINED(f,
sizeof(block_*));
110 if (free_start_ + size_ > free_end_)
113 void* res = free_start_;
114 free_start_ += size_;
115 #if SPOT_DEBUG && defined(HAVE_VALGRIND_MEMCHECK_H)
116 if (Kind == pool_type::Safe)
118 VALGRIND_MALLOCLIKE_BLOCK(res, size_, 0,
false);
134 block_* b =
reinterpret_cast<block_*
>(ptr);
137 #if SPOT_DEBUG && defined(HAVE_VALGRIND_MEMCHECK_H)
138 if (Kind == pool_type::Safe)
140 VALGRIND_FREELIKE_BLOCK(ptr, 0);
148 const size_t requested = (size_ > 128 ? size_ : 128) * 8192 - 64;
149 chunk_* c =
reinterpret_cast<chunk_*
>(::operator
new(requested));
150 c->prev = chunklist_;
153 free_start_ = c->data_ + size_;
154 free_end_ = c->data_ + requested;
159 struct block_ { block_* next; }* freelist_;
163 union chunk_ { chunk_* prev;
char data_[1]; }* chunklist_;
A fixed-size memory pool implementation.
Definition: fixpool.hh:45
void * allocate()
Allocate size bytes of memory.
Definition: fixpool.hh:87
void deallocate(void *ptr)
Recycle size bytes of memory.
Definition: fixpool.hh:131
~fixed_size_pool()
Free any memory allocated by this pool.
Definition: fixpool.hh:75
fixed_size_pool(size_t size)
Create a pool allocating objects of size bytes.
Definition: fixpool.hh:48
Definition: automata.hh:27
pool_type
Definition: fixpool.hh:40