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 flags=DefaultSlabPoolFlags) | |
Initialize. More... | |
size_t | object_size () const |
Get size of objects in pool. 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 | 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 65 of file slab_pool.h.
|
inlineexplicit |
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 arenaflags
defines options to modify behaviour as indicated in SlabPoolFlags Definition at line 76 of file slab_pool.h.
|
inlinevirtual |
Allocate memory for an object.
Implements roc::core::IPool.
Definition at line 103 of file slab_pool.h.
|
inlinevirtual |
|
inline |
Get number of guard failures detected.
Definition at line 113 of file slab_pool.h.
|
inlinevirtual |
Get size of objects in pool.
Implements roc::core::IPool.
Definition at line 93 of file slab_pool.h.
|
inlinevirtual |
Reserve memory for given number of objects.
Implements roc::core::IPool.
Definition at line 98 of file slab_pool.h.