join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicBumpAllocator< Backend, Capacity, SyncPolicy > Class Template Reference

bump allocator owning its backends. More...

#include <bump_allocator.hpp>

Public Member Functions

template<typename... Args>
 BasicBumpAllocator (Args &&... args)
 create instance.
 
 BasicBumpAllocator (const BasicBumpAllocator &other)=delete
 copy constructor.
 
BasicBumpAllocator & operator= (const BasicBumpAllocator &other)=delete
 copy assignment operator.
 
 BasicBumpAllocator (BasicBumpAllocator &&other) noexcept
 move constructor.
 
BasicBumpAllocator & operator= (BasicBumpAllocator &&other) noexcept
 move assignment operator.
 
 ~BasicBumpAllocator ()
 destroy instance.
 
void * allocate (size_t size) noexcept
 allocate memory at the cursor, aligned on the largest power of 2 dividing size, up to max_align_t.
 
void * allocate (size_t size, size_t alignment) noexcept
 allocate memory at the cursor with an explicit alignment.
 
void deallocate (void *p, size_t size) noexcept
 release memory (no-op).
 
void reset () noexcept
 release all allocations at once.
 
size_t used () const noexcept
 get the number of bytes consumed in the current block, alignment padding included.
 
bool hasBackend () const noexcept
 check if the bump allocator still owns a memory region.
 
int mlock () const noexcept
 lock the current block in RAM.
 

Static Public Member Functions

static constexpr size_t capacity () noexcept
 get the initial capacity.
 

Detailed Description

template<typename Backend, size_t Capacity, typename SyncPolicy>
class join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >

bump allocator owning its backends.

Constructor & Destructor Documentation

◆ BasicBumpAllocator() [1/3]

template<typename Backend , size_t Capacity, typename SyncPolicy >
template<typename... Args>
join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::BasicBumpAllocator ( Args &&... args)
inline

create instance.

Parameters
argsarguments forwarded to the backend.
Exceptions
std::system_errorif the backend cannot be mapped.

◆ BasicBumpAllocator() [2/3]

template<typename Backend , size_t Capacity, typename SyncPolicy >
join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::BasicBumpAllocator ( const BasicBumpAllocator< Backend, Capacity, SyncPolicy > & other)
delete

copy constructor.

Parameters
otherother object to copy.

◆ BasicBumpAllocator() [3/3]

template<typename Backend , size_t Capacity, typename SyncPolicy >
join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::BasicBumpAllocator ( BasicBumpAllocator< Backend, Capacity, SyncPolicy > && other)
inlinenoexcept

move constructor.

Parameters
otherother object to move.

◆ ~BasicBumpAllocator()

template<typename Backend , size_t Capacity, typename SyncPolicy >
join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::~BasicBumpAllocator ( )
inline

destroy instance.

Member Function Documentation

◆ allocate() [1/2]

template<typename Backend , size_t Capacity, typename SyncPolicy >
void * join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::allocate ( size_t size)
inlinenoexcept

allocate memory at the cursor, aligned on the largest power of 2 dividing size, up to max_align_t.

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

◆ allocate() [2/2]

template<typename Backend , size_t Capacity, typename SyncPolicy >
void * join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::allocate ( size_t size,
size_t alignment )
inlinenoexcept

allocate memory at the cursor with an explicit alignment.

Parameters
sizesize of the allocation request in bytes.
alignmentalignment of the allocation, must be a power of 2.
Returns
pointer to the allocated memory, or nullptr on failure.

◆ capacity()

template<typename Backend , size_t Capacity, typename SyncPolicy >
static constexpr size_t join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::capacity ( )
inlinestaticconstexprnoexcept

get the initial capacity.

Returns
capacity in bytes.

◆ deallocate()

template<typename Backend , size_t Capacity, typename SyncPolicy >
void join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::deallocate ( void * p,
size_t size )
inlinenoexcept

release memory (no-op).

Parameters
pmemory to release.
sizeallocation size (ignored).

◆ hasBackend()

template<typename Backend , size_t Capacity, typename SyncPolicy >
bool join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::hasBackend ( ) const
inlinenoexcept

check if the bump allocator still owns a memory region.

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

◆ mlock()

template<typename Backend , size_t Capacity, typename SyncPolicy >
int join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::mlock ( ) const
inlinenoexcept

lock the current block in RAM.

Returns
0 on success, -1 on failure.

◆ operator=() [1/2]

template<typename Backend , size_t Capacity, typename SyncPolicy >
BasicBumpAllocator & join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::operator= ( BasicBumpAllocator< Backend, Capacity, SyncPolicy > && other)
inlinenoexcept

move assignment operator.

Parameters
otherother object to move.
Returns
this.

◆ operator=() [2/2]

template<typename Backend , size_t Capacity, typename SyncPolicy >
BasicBumpAllocator & join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::operator= ( const BasicBumpAllocator< Backend, Capacity, SyncPolicy > & other)
delete

copy assignment operator.

Parameters
otherother object to copy.

◆ reset()

template<typename Backend , size_t Capacity, typename SyncPolicy >
void join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::reset ( )
inlinenoexcept

release all allocations at once.

◆ used()

template<typename Backend , size_t Capacity, typename SyncPolicy >
size_t join::BasicBumpAllocator< Backend, Capacity, SyncPolicy >::used ( ) const
inlinenoexcept

get the number of bytes consumed in the current block, alignment padding included.

Returns
consumed bytes.

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