22 #include <spot/misc/common.hh>
23 #include <spot/misc/clz.hh>
25 #if SPOT_DEBUG && __has_include(<valgrind/memcheck.h>)
26 #undef USES_MEMCHECK_H
27 #define USES_MEMCHECK_H 1
28 #include <valgrind/memcheck.h>
45 template<pool_type Kind>
56 if (size <
sizeof(block_))
57 size =
sizeof(block_);
59 if (!(size & (size-1)))
62 else if (size <
alignof(std::max_align_t))
63 return size_t{1} << (CHAR_BIT*
sizeof(size_t) - clz(size));
66 size_t mask =
alignof(std::max_align_t)-1;
67 return (size + mask) & ~mask;
81 chunk_* prev = chunklist_->prev;
82 ::operator
delete(chunklist_);
91 block_* f = freelist_;
95 #ifdef USES_MEMCHECK_H
96 if (Kind == pool_type::Safe)
98 VALGRIND_MALLOCLIKE_BLOCK(f, size_, 0,
false);
101 VALGRIND_MAKE_MEM_DEFINED(f,
sizeof(block_*));
112 if (free_start_ + size_ > free_end_)
115 void* res = free_start_;
116 free_start_ += size_;
117 #ifdef USES_MEMCHECK_H
118 if (Kind == pool_type::Safe)
120 VALGRIND_MALLOCLIKE_BLOCK(res, size_, 0,
false);
136 block_* b =
reinterpret_cast<block_*
>(ptr);
139 #ifdef USES_MEMCHECK_H
140 if (Kind == pool_type::Safe)
142 VALGRIND_FREELIKE_BLOCK(ptr, 0);
150 const size_t requested = (size_ > 128 ? size_ : 128) * 8192 - 64;
151 chunk_* c =
reinterpret_cast<chunk_*
>(::operator
new(requested));
152 c->prev = chunklist_;
155 free_start_ = c->data_ + size_;
156 free_end_ = c->data_ + requested;
161 struct block_ { block_* next; }* freelist_;
165 union chunk_ { chunk_* prev;
char data_[1]; }* chunklist_;
A fixed-size memory pool implementation.
Definition: fixpool.hh:47
void * allocate()
Allocate size bytes of memory.
Definition: fixpool.hh:89
void deallocate(void *ptr)
Recycle size bytes of memory.
Definition: fixpool.hh:133
~fixed_size_pool()
Free any memory allocated by this pool.
Definition: fixpool.hh:77
fixed_size_pool(size_t size)
Create a pool allocating objects of size bytes.
Definition: fixpool.hh:50
Definition: automata.hh:27
pool_type
Definition: fixpool.hh:42