8#include <gch/small_vector.hpp>
10#include "sleipnir/util/symbol_exports.hpp"
54 void*
allocate(
size_t bytes,
size_t alignment =
alignof(std::max_align_t));
65 size_t alignment =
alignof(std::max_align_t));
74 return this == &other;
81 size_t free_blocks = 0;
82 for (
const auto& pool : m_pools) {
83 free_blocks += pool.free_list.size();
85 return m_chunks.size() * blocks_per_chunk - free_blocks;
95 gch::small_vector<void*> free_list;
107 gch::small_vector<std::unique_ptr<std::byte[]>> m_buffer;
110 gch::small_vector<Chunk> m_chunks;
112 gch::small_vector<Pool> m_pools;
113 size_t blocks_per_chunk;
119 Pool& get_pool(
size_t block_size);
125 void add_chunk(Pool& pool);
156 return static_cast<T*
>(
157 m_memory_resource->
allocate(n *
sizeof(T),
alignof(T)));
165 m_memory_resource->
deallocate(p, n *
sizeof(T),
alignof(T));
173SLEIPNIR_DLLEXPORT PoolResource& global_pool_resource();
179PoolAllocator<T> global_pool_allocator() {
180 return PoolAllocator<T>{&global_pool_resource()};
constexpr PoolAllocator(const PoolAllocator< T > &)=default
Copy constructor.
constexpr PoolAllocator(PoolResource *r)
Definition pool.hpp:140
constexpr void deallocate(T *p, size_t n)
Definition pool.hpp:164
constexpr PoolAllocator< T > & operator=(const PoolAllocator< T > &)=default
T value_type
The type of object in the pool.
Definition pool.hpp:135
constexpr T * allocate(size_t n)
Definition pool.hpp:155
PoolResource(size_t blocks_per_chunk)
void * allocate(size_t bytes, size_t alignment=alignof(std::max_align_t))
bool is_equal(const PoolResource &other) const noexcept
Definition pool.hpp:73
PoolResource & operator=(PoolResource &&)
PoolResource(const PoolResource &)=delete
Copy constructor.
size_t blocks_in_use() const noexcept
Definition pool.hpp:80
PoolResource(PoolResource &&)
Move constructor.
PoolResource & operator=(const PoolResource &)=delete
void deallocate(void *p, size_t bytes, size_t alignment=alignof(std::max_align_t))
~PoolResource()
Destructor.