12 #ifndef ROC_CORE_SLAB_POOL_IMPL_H_
13 #define ROC_CORE_SLAB_POOL_IMPL_H_
63 size_t min_alloc_bytes,
64 size_t max_alloc_bytes,
65 void* preallocated_data,
66 size_t preallocated_size,
94 void* give_slot_to_user_(Slot* slot);
95 Slot* take_slot_from_user_(
void* memory);
97 Slot* acquire_slot_();
98 void release_slot_(Slot* slot);
99 bool reserve_slots_(
size_t desired_slots);
101 void increase_slab_size_(
size_t desired_n_slots);
102 bool allocate_new_slab_();
103 void deallocate_everything_();
105 void add_preallocated_memory_(
void* memory,
size_t memory_size);
107 size_t slots_per_slab_(
size_t slab_size,
bool round_up)
const;
108 size_t slot_offset_(
size_t slot_index)
const;
110 bool report_guard_(
size_t guard)
const;
117 List<Slab, NoOwnership> slabs_;
118 List<Slot, NoOwnership> free_slots_;
119 size_t n_used_slots_;
121 const size_t slab_min_bytes_;
122 const size_t slab_max_bytes_;
124 const size_t unaligned_slot_size_;
125 const size_t slot_size_;
126 const size_t slab_hdr_size_;
128 size_t slab_cur_slots_;
129 const size_t slab_max_slots_;
131 const size_t object_size_;
132 const size_t object_size_padding_;
134 const size_t guards_;
135 mutable size_t num_guard_failures_;
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Base class for List element.
Base class for non-copyable objects.
Memory pool implementation class.
ROC_ATTR_NODISCARD bool reserve(size_t n_objects)
Reserve memory for given number of objects.
void deallocate(void *memory)
Return memory to pool.
SlabPoolImpl(const char *name, IArena &arena, size_t object_size, size_t min_alloc_bytes, size_t max_alloc_bytes, void *preallocated_data, size_t preallocated_size, size_t guards)
Initialize.
size_t object_size() const
Get size of the object.
size_t num_guard_failures() const
Get number of guard failures.
void * allocate()
Allocate memory for an object.
size_t allocation_size() const
Get size of the allocation per object.
AlignMax SlotCanary
Canary guard which surrounds variable-length data.
~SlabPoolImpl()
Deinitialize.
Intrusive doubly-linked list.
Commonly used types and functions.
Maximum aligned data unit.