join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicSlabPool< Count, Size > Struct Template Reference

free-list pool operating over a pre-existing memory region. More...

#include <slab_allocator.hpp>

Collaboration diagram for join::BasicSlabPool< Count, Size >:

Public Types

using Chunk = BasicSlabChunk<Size>
 
using Segment = BasicSlabSegment<Size>
 

Public Member Functions

 BasicSlabPool (void *ptr) noexcept
 initialize the pool over an existing memory region.
 
 BasicSlabPool (const BasicSlabPool &other)=delete
 copy constructor.
 
BasicSlabPool & operator= (const BasicSlabPool &other)=delete
 copy assignment operator.
 
 BasicSlabPool (BasicSlabPool &&other) noexcept
 move constructor.
 
BasicSlabPool & operator= (BasicSlabPool &&other) noexcept
 move assignment operator.
 
 ~BasicSlabPool ()=default
 destroy instance.
 
void * pop () noexcept
 pop a chunk from the pool.
 
void push (void *p) noexcept
 push a chunk back to the pool.
 
bool reserveAll () noexcept
 reserve all chunks at once.
 
void releaseAll () noexcept
 release all chunks at once.
 
bool owns (void *p) const noexcept
 check if the pointer belongs to this pool.
 
uint32_t getIndex (void *p) const noexcept
 get the index of a chunk in the pool.
 
void * getPtr (uint32_t idx) const noexcept
 get the pointer to a chunk by index.
 

Public Attributes

Segment * _segment = nullptr
 pointer into the mapped region.
 

Static Public Attributes

static constexpr size_t _count = Count
 total number of chunks per pool.
 
static constexpr size_t _size = Size
 size of each chunk in bytes.
 
static constexpr size_t _stride = sizeof (Chunk)
 size in bytes between two consecutive chunks.
 
static constexpr size_t _total = sizeof (Segment) + _stride * _count
 total bytes required in the mapped region for this pool.
 

Detailed Description

template<size_t Count, size_t Size>
struct join::BasicSlabPool< Count, Size >

free-list pool operating over a pre-existing memory region.

Member Typedef Documentation

◆ Chunk

template<size_t Count, size_t Size>
using join::BasicSlabPool< Count, Size >::Chunk = BasicSlabChunk<Size>

◆ Segment

template<size_t Count, size_t Size>
using join::BasicSlabPool< Count, Size >::Segment = BasicSlabSegment<Size>

Constructor & Destructor Documentation

◆ BasicSlabPool() [1/3]

template<size_t Count, size_t Size>
join::BasicSlabPool< Count, Size >::BasicSlabPool ( void * ptr)
inlineexplicitnoexcept

initialize the pool over an existing memory region.

Parameters
ptrpointer to the start of the region.

◆ BasicSlabPool() [2/3]

template<size_t Count, size_t Size>
join::BasicSlabPool< Count, Size >::BasicSlabPool ( const BasicSlabPool< Count, Size > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicSlabPool() [3/3]

template<size_t Count, size_t Size>
join::BasicSlabPool< Count, Size >::BasicSlabPool ( BasicSlabPool< Count, Size > && other)
inlinenoexcept

move constructor.

Parameters
otherother object to move.

◆ ~BasicSlabPool()

template<size_t Count, size_t Size>
join::BasicSlabPool< Count, Size >::~BasicSlabPool ( )
default

destroy instance.

Member Function Documentation

◆ getIndex()

template<size_t Count, size_t Size>
uint32_t join::BasicSlabPool< Count, Size >::getIndex ( void * p) const
inlinenoexcept

get the index of a chunk in the pool.

Parameters
ppointer to the chunk (must be owned by this pool).
Returns
index of the chunk.

◆ getPtr()

template<size_t Count, size_t Size>
void * join::BasicSlabPool< Count, Size >::getPtr ( uint32_t idx) const
inlinenoexcept

get the pointer to a chunk by index.

Parameters
idxindex of the chunk (must be in range).
Returns
pointer to the chunk.

◆ operator=() [1/2]

template<size_t Count, size_t Size>
BasicSlabPool & join::BasicSlabPool< Count, Size >::operator= ( BasicSlabPool< Count, Size > && other)
inlinenoexcept

move assignment operator.

Parameters
otherother object to move.
Returns
this.

◆ operator=() [2/2]

template<size_t Count, size_t Size>
BasicSlabPool & join::BasicSlabPool< Count, Size >::operator= ( const BasicSlabPool< Count, Size > & other)
delete

copy assignment operator.

Parameters
otherother object to copy.

◆ owns()

template<size_t Count, size_t Size>
bool join::BasicSlabPool< Count, Size >::owns ( void * p) const
inlinenoexcept

check if the pointer belongs to this pool.

Parameters
ppointer to check.
Returns
true if the pointer belongs to this pool, false otherwise.

◆ pop()

template<size_t Count, size_t Size>
void * join::BasicSlabPool< Count, Size >::pop ( )
inlinenoexcept

pop a chunk from the pool.

Returns
pointer to the chunk, or nullptr if exhausted.

◆ push()

template<size_t Count, size_t Size>
void join::BasicSlabPool< Count, Size >::push ( void * p)
inlinenoexcept

push a chunk back to the pool.

Parameters
ppointer to the chunk to return.

◆ releaseAll()

template<size_t Count, size_t Size>
void join::BasicSlabPool< Count, Size >::releaseAll ( )
inlinenoexcept

release all chunks at once.

◆ reserveAll()

template<size_t Count, size_t Size>
bool join::BasicSlabPool< Count, Size >::reserveAll ( )
inlinenoexcept

reserve all chunks at once.

Returns
true if all chunks were free and have been reserved, false otherwise.

Member Data Documentation

◆ _count

template<size_t Count, size_t Size>
size_t join::BasicSlabPool< Count, Size >::_count = Count
staticconstexpr

total number of chunks per pool.

◆ _segment

template<size_t Count, size_t Size>
Segment* join::BasicSlabPool< Count, Size >::_segment = nullptr

pointer into the mapped region.

◆ _size

template<size_t Count, size_t Size>
size_t join::BasicSlabPool< Count, Size >::_size = Size
staticconstexpr

size of each chunk in bytes.

◆ _stride

template<size_t Count, size_t Size>
size_t join::BasicSlabPool< Count, Size >::_stride = sizeof (Chunk)
staticconstexpr

size in bytes between two consecutive chunks.

◆ _total

template<size_t Count, size_t Size>
size_t join::BasicSlabPool< Count, Size >::_total = sizeof (Segment) + _stride * _count
staticconstexpr

total bytes required in the mapped region for this pool.


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