12#ifndef ROC_CORE_SLAB_POOL_H_
13#define ROC_CORE_SLAB_POOL_H_
49 size_t min_alloc_bytes = 0,
50 size_t max_alloc_bytes = 0);
83 enum { PoisonAllocated = 0x7a, PoisonDeallocated = 0x7d };
85 struct Slab : ListNode {};
86 struct Slot : ListNode {};
88 void* give_slot_to_user_(Slot* slot);
89 Slot* take_slot_from_user_(
void* memory);
91 Slot* acquire_slot_();
92 void release_slot_(Slot* slot);
93 bool reserve_slots_(
size_t desired_slots);
95 void increase_slab_size_(
size_t desired_n_slots);
96 bool allocate_new_slab_();
97 void deallocate_everything_();
99 size_t slots_per_slab_(
size_t slab_size,
bool round_up)
const;
100 size_t slot_offset_(
size_t slot_index)
const;
104 IAllocator& allocator_;
106 List<Slab, NoOwnership> slabs_;
107 List<Slot, NoOwnership> free_slots_;
108 size_t n_used_slots_;
110 const size_t slab_min_bytes_;
111 const size_t slab_max_bytes_;
113 const size_t slot_size_;
114 const size_t slab_hdr_size_;
116 size_t slab_cur_slots_;
117 const size_t slab_max_slots_;
119 const size_t object_size_;
131 return pool.allocate();
138 pool.deallocate(ptr);
Memory allocator interface.
Base class for non-copyable objects.
SlabPool(IAllocator &allocator, size_t object_size, bool poison, size_t min_alloc_bytes=0, size_t max_alloc_bytes=0)
Initialize.
void deallocate(void *memory)
Return memory to pool.
void * allocate()
Allocate memory for an object.
bool reserve(size_t n_objects)
Reserve memory for given number of objects.
void destroy_object(T &object)
Destroy object and deallocate its memory.
size_t object_size() const
Get size of objects in pool.
Memory allocator interface.
Intrusive doubly-linked list.
#define roc_panic_if_not(x)
Panic if condition is false.
Commonly used types and functions.