Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
roc::core::SlabPool Class Reference

Slab pool. More...

#include <slab_pool.h>

Inheritance diagram for roc::core::SlabPool:
roc::core::NonCopyable< T >

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SlabPool()

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 slabs
  • object_size defines size of single object in bytes
  • min_alloc_bytes defines minimum size in bytes per request to allocator
  • max_alloc_bytes defines maximum size in bytes per request to allocator
  • poison enables memory poisoning for debugging

◆ ~SlabPool()

roc::core::SlabPool::~SlabPool ( )

Deinitialize.

Member Function Documentation

◆ allocate()

void * roc::core::SlabPool::allocate ( )

Allocate memory for an object.

Returns
pointer to a maximum aligned uninitialized memory for a new object or NULL if memory can't be allocated.

◆ deallocate()

void roc::core::SlabPool::deallocate ( void *  memory)

Return memory to pool.

◆ destroy_object()

template<class T >
void roc::core::SlabPool::destroy_object ( T &  object)
inline

Destroy object and deallocate its memory.

Definition at line 73 of file slab_pool.h.

◆ object_size()

size_t roc::core::SlabPool::object_size ( ) const

Get size of objects in pool.

◆ reserve()

bool roc::core::SlabPool::reserve ( size_t  n_objects)

Reserve memory for given number of objects.

Returns
false if allocation failed.

The documentation for this class was generated from the following file: