bit::memory
Public Types | Public Member Functions | List of all members
bit::memory::stack_block_allocator< BlockSize, Blocks, Align > Class Template Reference

An allocator with automatic storage reclamation. More...

#include <stack_block_allocator.hpp>

Public Types

using block_size = std::integral_constant< std::size_t, BlockSize >
 
using block_alignment = std::integral_constant< std::size_t, Align >
 

Public Member Functions

 stack_block_allocator () noexcept
 Constructs a stack_block_allocator that will distribute blocks of the specified size. More...
 
 stack_block_allocator (stack_block_allocator &&other)=delete
 
 stack_block_allocator (const stack_block_allocator &other)=delete
 
stack_block_allocatoroperator= (stack_block_allocator &&other)=delete
 
stack_block_allocatoroperator= (const stack_block_allocator &other)=delete
 
owner< memory_blockallocate_block () noexcept
 Allocates stack memory. More...
 
void deallocate_block (owner< memory_block > block) noexcept
 Deallocates a stack memory block. More...
 
std::size_t next_block_size () const noexcept
 Queries the next block size expected from this allocator. More...
 
allocator_info info () const noexcept
 Gets the info about this allocator. More...
 

Detailed Description

template<std::size_t BlockSize, std::size_t Blocks = 1u, std::size_t Align = alignof(std::max_align_t)>
class bit::memory::stack_block_allocator< BlockSize, Blocks, Align >

An allocator with automatic storage reclamation.

Memory is allocated from the stack, rather than from the heap.

Note
Caution should be used when allocating memory from the stack, otherwise a stack-overflow condition may occur
Template Parameters
BlockSizeThe size of each block
Blocksthe number of blocks in the block allocator
Alignthe alignment of the blocks
Satisfies
BlockAllocator

Definition at line 69 of file stack_block_allocator.hpp.

Constructor & Destructor Documentation

◆ stack_block_allocator()

template<std::size_t BlockSize, std::size_t Blocks = 1u, std::size_t Align = alignof(std::max_align_t)>
bit::memory::stack_block_allocator< BlockSize, Blocks, Align >::stack_block_allocator ( )
explicitnoexcept

Constructs a stack_block_allocator that will distribute blocks of the specified size.

Parameters
sizethe size of each block allocation

Member Function Documentation

◆ allocate_block()

template<std::size_t BlockSize, std::size_t Blocks = 1u, std::size_t Align = alignof(std::max_align_t)>
owner<memory_block> bit::memory::stack_block_allocator< BlockSize, Blocks, Align >::allocate_block ( )
noexcept

Allocates stack memory.

Returns
the memory block

◆ deallocate_block()

template<std::size_t BlockSize, std::size_t Blocks = 1u, std::size_t Align = alignof(std::max_align_t)>
void bit::memory::stack_block_allocator< BlockSize, Blocks, Align >::deallocate_block ( owner< memory_block block)
noexcept

Deallocates a stack memory block.

Note
This call is unnecessary, since the stack_block_allocator has automatic RAII cleanup.
Parameters
blockthe block to deallocate

◆ info()

template<std::size_t BlockSize, std::size_t Blocks = 1u, std::size_t Align = alignof(std::max_align_t)>
allocator_info bit::memory::stack_block_allocator< BlockSize, Blocks, Align >::info ( ) const
noexcept

Gets the info about this allocator.

This defaults to 'stack_block_allocator'. Use a named_stack_block_allocator to override this

Returns
the info for this allocator

◆ next_block_size()

template<std::size_t BlockSize, std::size_t Blocks = 1u, std::size_t Align = alignof(std::max_align_t)>
std::size_t bit::memory::stack_block_allocator< BlockSize, Blocks, Align >::next_block_size ( ) const
noexcept

Queries the next block size expected from this allocator.

Returns
the size of the next allocated block

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