bit::memory
Public Types | Public Member Functions | List of all members
bit::memory::bump_down_lifo_allocator Class Reference

An allocator that allocates memory in contiguous memory by 'bumping' the head pointer to lower memory addresses. More...

#include <bump_down_lifo_allocator.hpp>

Public Types

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

Public Member Functions

 bump_down_lifo_allocator (memory_block block) noexcept
 Constructs a linear_allocator.
 
 bump_down_lifo_allocator (bump_down_lifo_allocator &&other) noexcept=default
 Move-constructs a linear_allocator from another allocator. More...
 
 bump_down_lifo_allocator (const bump_down_lifo_allocator &other)=delete
 
 bump_down_lifo_allocator (nullblock_t)=delete
 
bump_down_lifo_allocatoroperator= (const bump_down_lifo_allocator &)=delete
 
bump_down_lifo_allocatoroperator= (bump_down_lifo_allocator &&other)=delete
 
owner< 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 (owner< void *> p, std::size_t size)
 Does nothing for linear_allocator. Use deallocate_all. More...
 
void deallocate_all () noexcept
 Deallocates everything from 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

An allocator that allocates memory in contiguous memory by 'bumping' the head pointer to lower memory addresses.

Allocations are distributed in a decreasing memory-address pattern.

This allocator offers 2 options for deallocations:

The two forms of deallocations are incompatible; either truncated deallocations can be used OR LIFO deallocations can be used.

Note
The bump_down_lifo_allocator requires an additional byte for restorying the bump pointer to the original location after deallocation. This can lead to a high-degree of fragmentation when allocating small-sized chunks of memory with high-allignment requirements.
Satisfies
ExtendedAllocator

Definition at line 73 of file bump_down_lifo_allocator.hpp.

Constructor & Destructor Documentation

◆ bump_down_lifo_allocator()

bit::memory::bump_down_lifo_allocator::bump_down_lifo_allocator ( bump_down_lifo_allocator &&  other)
defaultnoexcept

Move-constructs a linear_allocator from another allocator.

Parameters
otherthe other linear_allocator to move

Member Function Documentation

◆ deallocate()

void bit::memory::bump_down_lifo_allocator::deallocate ( owner< void *>  p,
std::size_t  size 
)

Does nothing for linear_allocator. Use deallocate_all.

Parameters
pthe pointer
sizethe size of the allocation

◆ info()

allocator_info bit::memory::bump_down_lifo_allocator::info ( ) const
noexcept

Gets the info about this allocator.

This defaults to 'bump_down_lifo_allocator'. Use a named_bump_down_lifo_allocator to override this

Returns
the info for this allocator

◆ owns()

bool bit::memory::bump_down_lifo_allocator::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()

owner<void*> bit::memory::bump_down_lifo_allocator::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: