![]() |
Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
|
Slab pool. More...
#include <slab_pool.h>
Public Member Functions | |
SlabPool (IAllocator &allocator, size_t object_size, bool poison, size_t min_alloc_bytes=0, size_t max_alloc_bytes=0) | |
Initialize. | |
~SlabPool () | |
Deinitialize. | |
size_t | object_size () const |
Get size of objects in pool. | |
bool | reserve (size_t n_objects) |
Reserve memory for given number of objects. | |
void * | allocate () |
Allocate memory for an object. | |
void | deallocate (void *memory) |
Return memory to pool. | |
template<class T > | |
void | destroy_object (T &object) |
Destroy object and deallocate its memory. | |
Slab pool.
Allocates large chunks of memory ("slabs") from given allocator suitable to hold multiple fixed-size objects ("slots").
Keeps track of free slots and use them when possible. Automatically allocates new slabs when there are no free slots.
Automatically grows size of new slabs exponentially. The user can also specify the minimum and maximum limits for the slab.
The return memory is always maximum aligned. Thread-safe.
Definition at line 36 of file slab_pool.h.
roc::core::SlabPool::SlabPool | ( | IAllocator & | allocator, |
size_t | object_size, | ||
bool | poison, | ||
size_t | min_alloc_bytes = 0 , |
||
size_t | max_alloc_bytes = 0 |
||
) |
Initialize.
Parameters
allocator
is used to allocate slabsobject_size
defines size of single object in bytesmin_alloc_bytes
defines minimum size in bytes per request to allocatormax_alloc_bytes
defines maximum size in bytes per request to allocatorpoison
enables memory poisoning for debugging roc::core::SlabPool::~SlabPool | ( | ) |
Deinitialize.
void * roc::core::SlabPool::allocate | ( | ) |
Allocate memory for an object.
void roc::core::SlabPool::deallocate | ( | void * | memory | ) |
Return memory to pool.
|
inline |
Destroy object and deallocate its memory.
Definition at line 73 of file slab_pool.h.
size_t roc::core::SlabPool::object_size | ( | ) | const |
Get size of objects in pool.
bool roc::core::SlabPool::reserve | ( | size_t | n_objects | ) |
Reserve memory for given number of objects.