Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
|
Memory pool. More...
#include <slab_pool.h>
Public Member Functions | |
SlabPool (const char *name, IArena &arena, size_t object_size=sizeof(T), size_t min_alloc_bytes=0, size_t max_alloc_bytes=0, size_t guards=SlabPool_DefaultGuards) | |
Initialize. More... | |
virtual size_t | allocation_size () const |
Get size of the allocation per object. More... | |
virtual size_t | object_size () const |
Get size of the object. More... | |
virtual ROC_ATTR_NODISCARD bool | reserve (size_t n_objects) |
Reserve memory for given number of objects. More... | |
virtual void * | allocate () |
Allocate memory for an object. More... | |
virtual void | deallocate (void *memory) |
Return memory to pool. More... | |
size_t | num_guard_failures () const |
Get number of guard failures detected. More... | |
Public Member Functions inherited from roc::core::IPool | |
template<class T > | |
void | destroy_object (T &object) |
Destroy object and deallocate its memory. More... | |
Memory pool.
Implements slab allocator algorithm. Allocates large chunks of memory ("slabs") from given arena, and uses them for multiple smaller fixed-sized objects ("slots").
Keeps track of free slots and uses them when possible. Automatically allocates new slabs when there are no free slots available.
Automatically grows size of new slabs exponentially. The user can also specify the minimum and maximum limits for the slabs.
The returned memory is always maximum-aligned.
Implements three safety measures:
T | defines pool object type. It is used to determine allocation size. If runtime size is different from static size of T, it can be provided via constructor. |
EmbeddedCapacity | defines number of slots embedded directly into SlabPool instance. If non-zero, this memory will be used for first allocations, before using memory arena. |
Thread-safe.
Definition at line 72 of file slab_pool.h.
|
inline |
Initialize.
Parameters
name
defines pool name, used for loggingarena
is used to allocate slabsobject_size
defines size of single object in bytesmin_alloc_bytes
defines minimum size in bytes per request to arenamax_alloc_bytes
defines maximum size in bytes per request to arenaguards
defines options to modify behaviour as indicated in SlabPoolGuard Definition at line 83 of file slab_pool.h.
|
inlinevirtual |
Allocate memory for an object.
Implements roc::core::IPool.
Definition at line 115 of file slab_pool.h.
|
inlinevirtual |
Get size of the allocation per object.
Implements roc::core::IPool.
Definition at line 100 of file slab_pool.h.
|
inlinevirtual |
|
inline |
Get number of guard failures detected.
Definition at line 125 of file slab_pool.h.
|
inlinevirtual |
|
inlinevirtual |
Reserve memory for given number of objects.
Implements roc::core::IPool.
Definition at line 110 of file slab_pool.h.