WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::growing_block_allocator< RawAllocator, Num, Den > Class Template Reference

A BlockAllocator that uses a given RawAllocator for allocating the blocks. More...

#include <wpi/memory/memory_arena.hpp>

Public Types

using allocator_type = typename traits::allocator_type
 

Public Member Functions

 growing_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
 

Static Public Member Functions

static float growth_factor () noexcept
 
static std::size_t grow_block_size (std::size_t block_size) noexcept
 

Detailed Description

template<class RawAllocator = default_allocator, unsigned Num = 2, unsigned Den = 1>
class wpi::memory::growing_block_allocator< RawAllocator, Num, Den >

A BlockAllocator that uses a given RawAllocator for allocating the blocks.

It calls the allocate_array() function with a node of size 1 and maximum alignment on the used allocator for the block allocation. The size of the next memory block will grow by a given factor after each allocation, allowing an amortized constant allocation time in the higher level allocator. The factor can be given as rational in the template parameter, default is 2.

Member Typedef Documentation

◆ allocator_type

template<class RawAllocator = default_allocator, unsigned Num = 2, unsigned Den = 1>
using wpi::memory::growing_block_allocator< RawAllocator, Num, Den >::allocator_type = typename traits::allocator_type

Constructor & Destructor Documentation

◆ growing_block_allocator()

template<class RawAllocator = default_allocator, unsigned Num = 2, unsigned Den = 1>
wpi::memory::growing_block_allocator< RawAllocator, Num, Den >::growing_block_allocator ( std::size_t block_size,
allocator_type alloc = allocator_type() )
inlineexplicitnoexcept
Effects:
Creates it by giving it the initial block size, the allocator object and the growth factor. By default, it uses a default-constructed allocator object and a growth factor of 2.
Requires:
block_size must be greater than 0.

Member Function Documentation

◆ allocate_block()

template<class RawAllocator = default_allocator, unsigned Num = 2, unsigned Den = 1>
memory_block wpi::memory::growing_block_allocator< RawAllocator, Num, Den >::allocate_block ( )
inline
Effects:
Allocates a new memory block and increases the block size for the next allocation.
Returns:
The new memory_block.
Throws:
Anything thrown by the allocate_array() function of the RawAllocator.

◆ deallocate_block()

template<class RawAllocator = default_allocator, unsigned Num = 2, unsigned Den = 1>
void wpi::memory::growing_block_allocator< RawAllocator, Num, Den >::deallocate_block ( memory_block block)
inlinenoexcept
Effects:
Deallocates a previously allocated memory block. This does not decrease the block size.
Requires:
block must be previously returned by a call to allocate_block().

◆ get_allocator()

template<class RawAllocator = default_allocator, unsigned Num = 2, unsigned Den = 1>
allocator_type & wpi::memory::growing_block_allocator< RawAllocator, Num, Den >::get_allocator ( )
inlinenoexcept
Returns:
A reference to the used RawAllocator object.

◆ grow_block_size()

template<class RawAllocator = default_allocator, unsigned Num = 2, unsigned Den = 1>
static std::size_t wpi::memory::growing_block_allocator< RawAllocator, Num, Den >::grow_block_size ( std::size_t block_size)
inlinestaticnoexcept

◆ growth_factor()

template<class RawAllocator = default_allocator, unsigned Num = 2, unsigned Den = 1>
static float wpi::memory::growing_block_allocator< RawAllocator, Num, Den >::growth_factor ( )
inlinestaticnoexcept
Returns:
The growth factor.

◆ next_block_size()

template<class RawAllocator = default_allocator, unsigned Num = 2, unsigned Den = 1>
std::size_t wpi::memory::growing_block_allocator< RawAllocator, Num, Den >::next_block_size ( ) const
inlinenoexcept
Returns:
The size of the memory block returned by the next call to allocate_block().

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