Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core::SlabPoolImpl Class Reference

Memory pool implementation class. More...

#include <slab_pool_impl.h>

Inheritance diagram for roc::core::SlabPoolImpl:
Collaboration diagram for roc::core::SlabPoolImpl:

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 flags)
 Initialize. More...
 
 ~SlabPoolImpl ()
 Deinitialize. 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. More...
 

Detailed Description

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 | SlotCanary | user data | SlotCanary |
+------------+------------+-----------+------------+
AlignMax SlotCanary
Canary guard which surrounds variable-length data.

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.

See also
SlabPool.

Definition at line 46 of file slab_pool_impl.h.

Member Typedef Documentation

◆ SlotCanary

Canary guard which surrounds variable-length data.

Definition at line 57 of file slab_pool_impl.h.

Constructor & Destructor Documentation

◆ SlabPoolImpl()

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  flags 
)

Initialize.

◆ ~SlabPoolImpl()

roc::core::SlabPoolImpl::~SlabPoolImpl ( )

Deinitialize.

Member Function Documentation

◆ allocate()

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

Allocate memory for an object.

◆ deallocate()

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

Return memory to pool.

◆ num_guard_failures()

size_t roc::core::SlabPoolImpl::num_guard_failures ( ) const

Get number of guard failures.

◆ object_size()

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

Get size of objects in pool.

◆ reserve()

ROC_ATTR_NODISCARD bool roc::core::SlabPoolImpl::reserve ( size_t  n_objects)

Reserve memory for given number of objects.


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