21#include <spot/misc/common.hh>
22#include <spot/misc/clz.hh>
24#if SPOT_DEBUG && __has_include(<valgrind/memcheck.h>)
26#define USES_MEMCHECK_H 1
27#include <valgrind/memcheck.h>
44 template<pool_type Kind>
55 if (size <
sizeof(block_))
56 size =
sizeof(block_);
58 if (!(size & (size-1)))
61 else if (size <
alignof(std::max_align_t))
62 return size_t{1} << (CHAR_BIT*
sizeof(size_t) - clz(size));
65 size_t mask =
alignof(std::max_align_t)-1;
66 return (size + mask) & ~mask;
80 chunk_* prev = chunklist_->prev;
81 ::operator
delete(chunklist_);
90 block_* f = freelist_;
95 if (Kind == pool_type::Safe)
97 VALGRIND_MALLOCLIKE_BLOCK(f, size_, 0,
false);
100 VALGRIND_MAKE_MEM_DEFINED(f,
sizeof(block_*));
111 if (free_start_ + size_ > free_end_)
114 void* res = free_start_;
115 free_start_ += size_;
116#ifdef USES_MEMCHECK_H
117 if (Kind == pool_type::Safe)
119 VALGRIND_MALLOCLIKE_BLOCK(res, size_, 0,
false);
135 block_* b =
reinterpret_cast<block_*
>(ptr);
138#ifdef USES_MEMCHECK_H
139 if (Kind == pool_type::Safe)
141 VALGRIND_FREELIKE_BLOCK(ptr, 0);
149 const size_t requested = (size_ > 128 ? size_ : 128) * 8192 - 64;
150 chunk_* c =
reinterpret_cast<chunk_*
>(::operator
new(requested));
151 c->prev = chunklist_;
154 free_start_ = c->data_ + size_;
155 free_end_ = c->data_ + requested;
160 struct block_ { block_* next; }* freelist_;
164 union chunk_ { chunk_* prev;
char data_[1]; }* chunklist_;
A fixed-size memory pool implementation.
Definition: fixpool.hh:46
void deallocate(void *ptr)
Recycle size bytes of memory.
Definition: fixpool.hh:132
~fixed_size_pool()
Free any memory allocated by this pool.
Definition: fixpool.hh:76
void * allocate()
Allocate size bytes of memory.
Definition: fixpool.hh:88
fixed_size_pool(size_t size)
Create a pool allocating objects of size bytes.
Definition: fixpool.hh:49
Definition: automata.hh:26
pool_type
Definition: fixpool.hh:41