40template<
typename T, di::concepts::FallibleAllocator Alloc = di::DefaultAllocator>
46 auto [storage, effective_capacity] =
48 pool.m_storage = storage;
49 pool.m_capacity = effective_capacity;
54 di::construct_at(&object.freed);
55 pool.m_free_list.push_front(object.freed);
64 : m_free_list(
di::move(other.m_free_list))
65 , m_storage(
di::
exchange(other.m_storage, nullptr))
66 , m_capacity(
di::
exchange(other.m_capacity, 0))
67 , m_allocator(
di::move(other.m_allocator)) {
68 ASSERT_EQ(m_capacity, m_free_list.size());
76 m_free_list = di::move(other.m_free_list);
79 m_allocator = di::move(other.m_allocator);
85 ASSERT_EQ(m_free_list.size(), m_capacity);
94 if (m_free_list.empty()) {
97 auto* freed_pointer = &*m_free_list.pop_front();
103 return internal_object->object;
112 m_free_list.push_front(internal_object->freed);
118 usize m_capacity { 0 };
119 [[no_unique_address]] Alloc m_allocator {};
#define ASSERT_EQ
Definition assert_binary.h:84
Definition forward_list_node.h:9
Definition forward_list_forward_declaration.h:12
Definition unexpected.h:14
~ObjectPool()
Definition object_pool.h:71
auto allocate() -> Expected< T & >
Definition object_pool.h:93
void deallocate(T &object)
Definition object_pool.h:106
ObjectPool(ObjectPool &&other)
Definition object_pool.h:63
auto operator=(ObjectPool &&other) -> ObjectPool &
Definition object_pool.h:73
void clear()
Definition object_pool.h:84
static auto create(usize requested_capacity) -> Expected< ObjectPool >
Definition object_pool.h:43
#define TRY
Definition monad_try.h:23
size_t usize
Definition integers.h:33
Definition zstring_parser.h:9
constexpr auto exchange(T &object, U &&new_value) -> T
Definition exchange.h:8
constexpr auto for_each
Definition for_each.h:31
constexpr auto destroy_at
Definition destroy_at.h:24
constexpr auto deallocate_many
Definition deallocate_many.h:28
constexpr auto uninitialized_default_construct
Definition uninitialized_default_construct.h:34
constexpr auto allocate_many
Definition allocate_many.h:48
constexpr auto construct_at
Definition construct_at.h:27
Definition object_pool.h:14
Definition cxx_init.cpp:12
@ NotEnoughMemory
Definition error.h:59
di::vocab::Expected< T, di::platform::GenericCode > Expected
Definition error.h:324
Definition forward_list.h:17
Definition in_place_type.h:5
Definition object_pool.h:22
Definition object_pool.h:15
static constexpr auto is_sized(di::InPlaceType< U >) -> bool
Definition object_pool.h:17
Definition object_pool.h:25
InternalObjectFreed freed
Definition object_pool.h:29
InternalObject()
Definition object_pool.h:26
T object
Definition object_pool.h:28