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

A BlockAllocator that reserves virtual memory and commits it part by part. More...

#include <wpi/memory/virtual_memory.hpp>

Public Member Functions

 virtual_block_allocator (std::size_t block_size, std::size_t no_blocks)
 
 ~virtual_block_allocator () noexcept
 
memory_block allocate_block ()
 
void deallocate_block (memory_block block) noexcept
 
std::size_t next_block_size () const noexcept
 
std::size_t capacity_left () const noexcept
 
 virtual_block_allocator (virtual_block_allocator &&other) noexcept
 
virtual_block_allocatoroperator= (virtual_block_allocator &&other) noexcept
 

Friends

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

Detailed Description

A BlockAllocator that reserves virtual memory and commits it part by part.

It is similar to memory_stack but does not support growing and uses virtual memory, also meant for big blocks not small allocations.

Constructor & Destructor Documentation

◆ virtual_block_allocator() [1/2]

wpi::memory::virtual_block_allocator::virtual_block_allocator ( std::size_t block_size,
std::size_t no_blocks )
explicit
Effects:
Creates it giving it the block size and the total number of blocks it can allocate. It reserves enough virtual memory for block_size * no_blocks.
Requires:
block_size must be non-zero and a multiple of the virtual_memory_page_size. no_blocks must be bigger than 1.
Throws:
out_of_memory if it cannot reserve the virtual memory.

◆ ~virtual_block_allocator()

wpi::memory::virtual_block_allocator::~virtual_block_allocator ( )
noexcept
Effects:
Releases the reserved virtual memory.

◆ virtual_block_allocator() [2/2]

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

Member Function Documentation

◆ allocate_block()

memory_block wpi::memory::virtual_block_allocator::allocate_block ( )
Effects:
Allocates a new memory block by committing the next next_block_size() number of bytes.
Returns:
The memory_block committed.
Throws:
out_of_memory if it cannot commit the memory or the capacity_left() is exhausted.

◆ capacity_left()

std::size_t wpi::memory::virtual_block_allocator::capacity_left ( ) const
inlinenoexcept
Returns:
The number of blocks that can be committed until it runs out of memory.

◆ deallocate_block()

void wpi::memory::virtual_block_allocator::deallocate_block ( memory_block block)
noexcept
Effects:
Deallocates the last allocated memory block by decommitting it. This block will be returned again on 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::virtual_block_allocator::next_block_size ( ) const
inlinenoexcept
Returns:
The next block size, this is the block size of the constructor.

◆ operator=()

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

Friends And Related Symbol Documentation

◆ swap

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

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