29 : blocks_per_chunk{blocks_per_chunk} {}
64 alignof(std::max_align_t)) {
65 if (m_free_list.empty()) {
69 auto ptr = m_free_list.back();
70 m_free_list.pop_back();
82 void* p, [[maybe_unused]]
size_t bytes,
83 [[maybe_unused]]
size_t alignment =
alignof(std::max_align_t)) {
84 m_free_list.emplace_back(p);
94 return this == &other;
103 return m_buffer.size() * blocks_per_chunk - m_free_list.size();
109 size_t blocks_per_chunk;
117 void add_chunk(
size_t bytes_per_block) {
118 m_buffer.
emplace_back(
new std::byte[bytes_per_block * blocks_per_chunk]);
119 for (
int i = blocks_per_chunk - 1; i >= 0; --i) {
165 return static_cast<T*
>(m_memory_resource->
allocate(n));
This class is an allocator for the pool resource.
Definition pool.hpp:131
constexpr PoolAllocator(const PoolAllocator< T > &)=default
Copy constructor.
constexpr PoolAllocator(PoolResource *r)
Constructs a pool allocator with the given pool memory resource.
Definition pool.hpp:143
constexpr void deallocate(T *p, size_t n)
Gives a block of memory back to the pool.
Definition pool.hpp:174
constexpr PoolAllocator< T > & operator=(const PoolAllocator< T > &)=default
Copy assignment operator.
T value_type
The type of object in the pool.
Definition pool.hpp:136
constexpr T * allocate(size_t n)
Returns a block of memory from the pool.
Definition pool.hpp:164
This class implements a pool memory resource.
Definition pool.hpp:21
PoolResource(size_t blocks_per_chunk)
Constructs a default PoolResource.
Definition pool.hpp:28
PoolResource(PoolResource &&)=default
Move constructor.
void * allocate(size_t bytes, size_t alignment=alignof(std::max_align_t))
Returns a block of memory from the pool.
Definition pool.hpp:63
bool is_equal(const PoolResource &other) const noexcept
Returns true if this pool resource has the same backing storage as another.
Definition pool.hpp:93
PoolResource(const PoolResource &)=delete
Copy constructor.
size_t blocks_in_use() const noexcept
Returns the number of blocks from this pool resource that are in use.
Definition pool.hpp:102
PoolResource & operator=(PoolResource &&)=default
Move assignment operator.
PoolResource & operator=(const PoolResource &)=delete
Copy assignment operator.
void deallocate(void *p, size_t bytes, size_t alignment=alignof(std::max_align_t))
Gives a block of memory back to the pool.
Definition pool.hpp:81
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition SmallVector.h:1198
reference emplace_back(ArgTypes &&... Args)
Definition SmallVector.h:939
reference back()
Definition SmallVector.h:310
Definition expression_graph.hpp:11
SLEIPNIR_DLLEXPORT PoolResource & global_pool_resource()
Returns a global pool memory resource.
PoolAllocator< T > global_pool_allocator()
Returns an allocator for a global pool memory resource.
Definition pool.hpp:193
#define SLEIPNIR_DLLEXPORT
Definition symbol_exports.hpp:34