Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
|
Memory pool implementation class. More...
#include <slab_pool_impl.h>
Classes | |
struct | SlotHeader |
Slot header. More... | |
Public Types | |
typedef AlignMax | SlotCanary |
Canary guard which surrounds variable-length data. More... | |
Public Member Functions | |
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. More... | |
~SlabPoolImpl () | |
Deinitialize. More... | |
ROC_ATTR_NODISCARD bool | reserve (size_t n_objects) |
Reserve memory for given number of objects. More... | |
void * | allocate () |
Allocate memory for an object. More... | |
void | deallocate (void *memory) |
Return memory to pool. More... | |
size_t | allocation_size () const |
Get size of the allocation per object. More... | |
size_t | object_size () const |
Get size of the object. More... | |
size_t | num_guard_failures () const |
Get number of guard failures. More... | |
Memory pool implementation class.
This is non-template class that implements all pool logic, to avoid polluting header file.
Allocated slots have the following format:
SlotHeader contains pointer to the owning pool, checked when returning memory to pool. SlotCanary contains magic bytes filled when returning memory to user, and checked when returning memory to pool.
If user data requires padding to be maximum-aligned, this padding also becomes part of the trailing canary guard.
Definition at line 46 of file slab_pool_impl.h.
Canary guard which surrounds variable-length data.
Definition at line 57 of file slab_pool_impl.h.
roc::core::SlabPoolImpl::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.
roc::core::SlabPoolImpl::~SlabPoolImpl | ( | ) |
Deinitialize.
void* roc::core::SlabPoolImpl::allocate | ( | ) |
Allocate memory for an object.
size_t roc::core::SlabPoolImpl::allocation_size | ( | ) | const |
Get size of the allocation per object.
void roc::core::SlabPoolImpl::deallocate | ( | void * | memory | ) |
Return memory to pool.
size_t roc::core::SlabPoolImpl::num_guard_failures | ( | ) | const |
Get number of guard failures.
size_t roc::core::SlabPoolImpl::object_size | ( | ) | const |
Get size of the object.
ROC_ATTR_NODISCARD bool roc::core::SlabPoolImpl::reserve | ( | size_t | n_objects | ) |
Reserve memory for given number of objects.