8#include <gch/small_vector.hpp>
10#include "sleipnir/util/symbol_exports.hpp"
25 : blocks_per_chunk{blocks_per_chunk} {}
50 alignof(std::max_align_t)) {
51 if (m_free_list.empty()) {
55 auto ptr = m_free_list.back();
56 m_free_list.pop_back();
68 m_free_list.emplace_back(
p);
78 return this == &
other;
85 return m_buffer.size() * blocks_per_chunk - m_free_list.size();
89 gch::small_vector<std::unique_ptr<std::byte[]>> m_buffer;
90 gch::small_vector<void*> m_free_list;
91 size_t blocks_per_chunk;
98 m_buffer.emplace_back(
new std::byte[
bytes_per_block * blocks_per_chunk]);
99 for (
int i = blocks_per_chunk - 1;
i >= 0; --
i) {
133 return static_cast<T*
>(m_memory_resource->
allocate(
n));
149SLEIPNIR_DLLEXPORT PoolResource& global_pool_resource();
155PoolAllocator<T> global_pool_allocator() {
156 return PoolAllocator<T>{&global_pool_resource()};
Definition intrusive_shared_ptr.hpp:27
constexpr PoolAllocator(const PoolAllocator< T > &)=default
Copy constructor.
constexpr PoolAllocator(PoolResource *r)
Definition pool.hpp:117
constexpr void deallocate(T *p, size_t n)
Definition pool.hpp:140
constexpr PoolAllocator< T > & operator=(const PoolAllocator< T > &)=default
T value_type
The type of object in the pool.
Definition pool.hpp:112
constexpr T * allocate(size_t n)
Definition pool.hpp:132
PoolResource(size_t blocks_per_chunk)
Definition pool.hpp:24
PoolResource(PoolResource &&)=default
Move constructor.
void * allocate(size_t bytes, size_t alignment=alignof(std::max_align_t))
Definition pool.hpp:49
bool is_equal(const PoolResource &other) const noexcept
Definition pool.hpp:77
PoolResource(const PoolResource &)=delete
Copy constructor.
size_t blocks_in_use() const noexcept
Definition pool.hpp:84
PoolResource & operator=(PoolResource &&)=default
PoolResource & operator=(const PoolResource &)=delete
void deallocate(void *p, size_t bytes, size_t alignment=alignof(std::max_align_t))
Definition pool.hpp:65