WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::static_block_allocator Class Reference

A BlockAllocator that allocates the blocks from a fixed size storage. More...

#include <wpi/memory/static_allocator.hpp>

Public Member Functions

template<std::size_t Size>
 static_block_allocator (std::size_t block_size, static_allocator_storage< Size > &storage) noexcept
 
 ~static_block_allocator () noexcept=default
 
memory_block allocate_block ()
 
void deallocate_block (memory_block block) noexcept
 
std::size_t next_block_size () const noexcept
 
 static_block_allocator (static_block_allocator &&other) noexcept
 
static_block_allocatoroperator= (static_block_allocator &&other) noexcept
 

Friends

void swap (static_block_allocator &a, static_block_allocator &b) noexcept
 

Detailed Description

A BlockAllocator that allocates the blocks from a fixed size storage.

It works on a static_allocator_storage and uses it for all allocations, deallocations are only allowed in reversed order which is guaranteed by memory_arena.

Note
It is not allowed to share an static_allocator_storage between multiple static_allocator objects.

Constructor & Destructor Documentation

◆ static_block_allocator() [1/2]

template<std::size_t Size>
wpi::memory::static_block_allocator::static_block_allocator ( std::size_t block_size,
static_allocator_storage< Size > & storage )
inlinenoexcept
Effects:
Creates it by passing it the block size and a static_allocator_storage by reference. It will take the address of the storage and use it to allocate block_size'd blocks.
Requires:
The storage object must live as long as the allocator object. It must not be shared between multiple allocators, i.e. the object must not have been passed to a constructor before. The size of the static_allocator_storage must be a multiple of the (non-null) block size.

◆ ~static_block_allocator()

wpi::memory::static_block_allocator::~static_block_allocator ( )
defaultnoexcept

◆ static_block_allocator() [2/2]

wpi::memory::static_block_allocator::static_block_allocator ( static_block_allocator && other)
inlinenoexcept
Effects:
Moves the block allocator, it transfers ownership over the static_allocator_storage. This does not invalidate any memory blocks.

Member Function Documentation

◆ allocate_block()

memory_block wpi::memory::static_block_allocator::allocate_block ( )
Effects:
Allocates a new block by returning the next_block_size() bytes.
Returns:
The new memory block.

◆ deallocate_block()

void wpi::memory::static_block_allocator::deallocate_block ( memory_block block)
noexcept
Effects:
Deallocates the last memory block by marking the block as free again. This block will be returned again by the next call to allocate_block().
Requires:
block must be the current top block of the memory, this is guaranteed by memory_arena.

◆ next_block_size()

std::size_t wpi::memory::static_block_allocator::next_block_size ( ) const
inlinenoexcept
Returns:
The next block size, this is the size passed to the constructor.

◆ operator=()

static_block_allocator & wpi::memory::static_block_allocator::operator= ( static_block_allocator && other)
inlinenoexcept

Friends And Related Symbol Documentation

◆ swap

void swap ( static_block_allocator & a,
static_block_allocator & b )
friend
Effects:
Swaps the ownership over the static_allocator_storage. This does not invalidate any memory blocks.

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