WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::fixed_block_allocator< RawAllocator > Class Template Reference

A BlockAllocator that allows only one block allocation. More...

#include <wpi/memory/memory_arena.hpp>

Public Types

using allocator_type = typename traits::allocator_type
 

Public Member Functions

 fixed_block_allocator (std::size_t block_size, allocator_type alloc=allocator_type()) noexcept
 
memory_block allocate_block ()
 
void deallocate_block (memory_block block) noexcept
 
std::size_t next_block_size () const noexcept
 
allocator_typeget_allocator () noexcept
 

Detailed Description

template<class RawAllocator = default_allocator>
class wpi::memory::fixed_block_allocator< RawAllocator >

A BlockAllocator that allows only one block allocation.

It can be used to prevent higher-level allocators from expanding. The one block allocation is performed through the allocate_array() function of the given RawAllocator.

Member Typedef Documentation

◆ allocator_type

template<class RawAllocator = default_allocator>
using wpi::memory::fixed_block_allocator< RawAllocator >::allocator_type = typename traits::allocator_type

Constructor & Destructor Documentation

◆ fixed_block_allocator()

template<class RawAllocator = default_allocator>
wpi::memory::fixed_block_allocator< RawAllocator >::fixed_block_allocator ( std::size_t block_size,
allocator_type alloc = allocator_type() )
inlineexplicitnoexcept
Effects:
Creates it by passing it the size of the block and the allocator object.
Requires:
block_size must be greater than 0,

Member Function Documentation

◆ allocate_block()

template<class RawAllocator = default_allocator>
memory_block wpi::memory::fixed_block_allocator< RawAllocator >::allocate_block ( )
inline
Effects:
Allocates a new memory block or throws an exception if there was already one allocation.
Returns:
The new memory_block.
Throws:
Anything thrown by the allocate_array() function of the RawAllocator or out_of_memory if this is not the first call.

◆ deallocate_block()

template<class RawAllocator = default_allocator>
void wpi::memory::fixed_block_allocator< RawAllocator >::deallocate_block ( memory_block block)
inlinenoexcept
Effects:
Deallocates the previously allocated memory block. It also resets and allows a new call again.

◆ get_allocator()

template<class RawAllocator = default_allocator>
allocator_type & wpi::memory::fixed_block_allocator< RawAllocator >::get_allocator ( )
inlinenoexcept
Returns:
A reference to the used RawAllocator object.

◆ next_block_size()

template<class RawAllocator = default_allocator>
std::size_t wpi::memory::fixed_block_allocator< RawAllocator >::next_block_size ( ) const
inlinenoexcept
Returns:
The size of the next block which is either the initial size or 0.

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