bit::memory
Public Types | Public Member Functions | List of all members
bit::memory::stack_allocator< Size, Align > Class Template Reference

A stack-allocation strategy that allocates off of stack-memory. More...

#include <stack_allocator.hpp>

Public Types

using max_alignment = std::integral_constant< std::size_t, Align >
 

Public Member Functions

 stack_allocator () noexcept
 Default-constructs a stack_allocator.
 
 stack_allocator (stack_allocator &&other)=delete
 
 stack_allocator (const stack_allocator &other)=delete
 
 ~stack_allocator ()
 Deallocates all memory from the stack.
 
stack_allocatoroperator= (const stack_allocator &)=delete
 
stack_allocatoroperator= (stack_allocator &&other)=delete
 
void * try_allocate (std::size_t size, std::size_t align, std::size_t offset=0) noexcept
 Tries to allocate memory of size size, aligned to the boundary align, offset by offset. More...
 
void deallocate (void *p, std::size_t size)
 Does nothing for linear_allocator. Use deallocate_all. More...
 
void deallocate_all ()
 Deallocates all memory in this allocator.
 
bool owns (const void *p) const noexcept
 Checks whether linear_allocator contains the pointer p. More...
 
allocator_info info () const noexcept
 Gets the info about this allocator. More...
 

Detailed Description

template<std::size_t Size, std::size_t Align = alignof(std::max_align_t)>
class bit::memory::stack_allocator< Size, Align >

A stack-allocation strategy that allocates off of stack-memory.

This offers two different forms of deallocations; either truncated deallocations via deallocate_all, or individual deallocations through deallocate(...) calls. The order of deallocation must be the inverse of the order of construction, otherwise it is undefined behaviour.

Note
Since this allocator uses stack memory, care should be taken to avoid overflowing the stack
Template Parameters
SizeThe size of the storage in this allocator
Alignthe alignment of the storage
Satisfies
ExtendedAllocator

Definition at line 66 of file stack_allocator.hpp.

Member Function Documentation

◆ deallocate()

template<std::size_t Size, std::size_t Align = alignof(std::max_align_t)>
void bit::memory::stack_allocator< Size, Align >::deallocate ( void *  p,
std::size_t  size 
)

Does nothing for linear_allocator. Use deallocate_all.

Parameters
pthe pointer
sizethe size of the allocation

◆ info()

template<std::size_t Size, std::size_t Align = alignof(std::max_align_t)>
allocator_info bit::memory::stack_allocator< Size, Align >::info ( ) const
noexcept

Gets the info about this allocator.

This defaults to 'stack_allocator'. Use a named_stack_allocator to override this

Returns
the info for this allocator

◆ owns()

template<std::size_t Size, std::size_t Align = alignof(std::max_align_t)>
bool bit::memory::stack_allocator< Size, Align >::owns ( const void *  p) const
noexcept

Checks whether linear_allocator contains the pointer p.

Parameters
pthe pointer to check
Returns
true if p is contained in this allocator

◆ try_allocate()

template<std::size_t Size, std::size_t Align = alignof(std::max_align_t)>
void* bit::memory::stack_allocator< Size, Align >::try_allocate ( std::size_t  size,
std::size_t  align,
std::size_t  offset = 0 
)
noexcept

Tries to allocate memory of size size, aligned to the boundary align, offset by offset.

Parameters
sizethe size of the allocation
alignthe requested alignment of the allocation
offsetthe amount to offset the alignment by
Returns
the allocated pointer on success, nullptr on failure

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