join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicArena< Backend, Count, Sizes > Class Template Reference

memory arena owning backend and managing one or more pools. More...

#include <allocator.hpp>

Public Member Functions

template<typename... Args>
 BasicArena (Args &&... args)
 create instance.
 
 BasicArena (const BasicArena &other)=delete
 copy constructor.
 
BasicArenaoperator= (const BasicArena &other)=delete
 copy assignment operator.
 
 BasicArena (BasicArena &&other) noexcept
 move constructor.
 
BasicArenaoperator= (BasicArena &&other) noexcept
 move assignment operator.
 
 ~BasicArena ()=default
 destroy instance.
 
void * allocate (size_t size) noexcept
 allocate memory from the first pool that fits (promotes if exhausted).
 
void * tryAllocate (size_t size) noexcept
 allocate memory from the exact pool that fits, without promotion.
 
void deallocate (void *p) noexcept
 return memory to the appropriate pool.
 
bool hasBackend () const noexcept
 check if the arena still owns a memory region.
 
template<size_t I = 0>
uint32_t getIndex (void *p) const noexcept
 get the index of a chunk in the pool.
 
template<size_t I = 0>
void * getPtr (uint32_t idx) const noexcept
 get the pointer to a chunk by index.
 
template<size_t I = 0>
bool reserveAll () noexcept
 reserve all chunks of a pool at once.
 
template<size_t I = 0>
void releaseAll () noexcept
 release all chunks of a pool at once.
 
int mlock () const noexcept
 lock memory in RAM.
 

Static Public Attributes

static constexpr size_t _total = TotalSize<Count, Sizes...>::value
 total bytes required in the mapped region.
 

Detailed Description

template<typename Backend, size_t Count, size_t... Sizes>
class join::BasicArena< Backend, Count, Sizes >

memory arena owning backend and managing one or more pools.

allocator forward declarations.

Constructor & Destructor Documentation

◆ BasicArena() [1/3]

template<typename Backend , size_t Count, size_t... Sizes>
template<typename... Args>
join::BasicArena< Backend, Count, Sizes >::BasicArena ( Args &&... args)
inline

create instance.

Parameters
argsarguments forwarded to the backend.

◆ BasicArena() [2/3]

template<typename Backend , size_t Count, size_t... Sizes>
join::BasicArena< Backend, Count, Sizes >::BasicArena ( const BasicArena< Backend, Count, Sizes > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicArena() [3/3]

template<typename Backend , size_t Count, size_t... Sizes>
join::BasicArena< Backend, Count, Sizes >::BasicArena ( BasicArena< Backend, Count, Sizes > && other)
inlinenoexcept

move constructor.

Parameters
otherother object to move.

◆ ~BasicArena()

template<typename Backend , size_t Count, size_t... Sizes>
join::BasicArena< Backend, Count, Sizes >::~BasicArena ( )
default

destroy instance.

Member Function Documentation

◆ allocate()

template<typename Backend , size_t Count, size_t... Sizes>
void * join::BasicArena< Backend, Count, Sizes >::allocate ( size_t size)
inlinenoexcept

allocate memory from the first pool that fits (promotes if exhausted).

Parameters
sizesize of the allocation request in bytes.
Returns
pointer to the allocated memory, or nullptr on failure.

◆ deallocate()

template<typename Backend , size_t Count, size_t... Sizes>
void join::BasicArena< Backend, Count, Sizes >::deallocate ( void * p)
inlinenoexcept

return memory to the appropriate pool.

Parameters
ppointer to the memory to return.

◆ getIndex()

template<typename Backend , size_t Count, size_t... Sizes>
template<size_t I = 0>
uint32_t join::BasicArena< Backend, Count, Sizes >::getIndex ( void * p) const
inlinenoexcept

get the index of a chunk in the pool.

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

◆ getPtr()

template<typename Backend , size_t Count, size_t... Sizes>
template<size_t I = 0>
void * join::BasicArena< Backend, Count, Sizes >::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.

◆ hasBackend()

template<typename Backend , size_t Count, size_t... Sizes>
bool join::BasicArena< Backend, Count, Sizes >::hasBackend ( ) const
inlinenoexcept

check if the arena still owns a memory region.

Returns
true if the arena owns a memory region, false if it has been moved from.

◆ mlock()

template<typename Backend , size_t Count, size_t... Sizes>
int join::BasicArena< Backend, Count, Sizes >::mlock ( ) const
inlinenoexcept

lock memory in RAM.

Returns
0 on success, -1 on failure.

◆ operator=() [1/2]

template<typename Backend , size_t Count, size_t... Sizes>
BasicArena & join::BasicArena< Backend, Count, Sizes >::operator= ( BasicArena< Backend, Count, Sizes > && other)
inlinenoexcept

move assignment operator.

Parameters
otherother object to move.
Returns
this.

◆ operator=() [2/2]

template<typename Backend , size_t Count, size_t... Sizes>
BasicArena & join::BasicArena< Backend, Count, Sizes >::operator= ( const BasicArena< Backend, Count, Sizes > & other)
delete

copy assignment operator.

Parameters
otherother object to copy.

◆ releaseAll()

template<typename Backend , size_t Count, size_t... Sizes>
template<size_t I = 0>
void join::BasicArena< Backend, Count, Sizes >::releaseAll ( )
inlinenoexcept

release all chunks of a pool at once.

◆ reserveAll()

template<typename Backend , size_t Count, size_t... Sizes>
template<size_t I = 0>
bool join::BasicArena< Backend, Count, Sizes >::reserveAll ( )
inlinenoexcept

reserve all chunks of a pool at once.

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

◆ tryAllocate()

template<typename Backend , size_t Count, size_t... Sizes>
void * join::BasicArena< Backend, Count, Sizes >::tryAllocate ( size_t size)
inlinenoexcept

allocate memory from the exact pool that fits, without promotion.

Parameters
sizesize of the allocation request in bytes.
Returns
pointer to the allocated memory, or nullptr on failure.

Member Data Documentation

◆ _total

template<typename Backend , size_t Count, size_t... Sizes>
size_t join::BasicArena< Backend, Count, Sizes >::_total = TotalSize<Count, Sizes...>::value
staticconstexpr

total bytes required in the mapped region.


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