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

A stateful RawAllocator that uses a fixed sized storage for the allocations. More...

#include <wpi/memory/static_allocator.hpp>

Public Types

using is_stateful = std::true_type
 

Public Member Functions

template<std::size_t Size>
 static_allocator (static_allocator_storage< Size > &storage) noexcept
 
void * allocate_node (std::size_t size, std::size_t alignment)
 
void deallocate_node (void *, std::size_t, std::size_t) noexcept
 
std::size_t max_node_size () const noexcept
 
std::size_t max_alignment () const noexcept
 

Detailed Description

A stateful RawAllocator that uses a fixed sized storage for the allocations.

It works on a static_allocator_storage and uses its memory for all allocations. Deallocations are not supported, memory cannot be marked as freed.

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

Member Typedef Documentation

◆ is_stateful

Constructor & Destructor Documentation

◆ static_allocator()

template<std::size_t Size>
wpi::memory::static_allocator::static_allocator ( static_allocator_storage< Size > & storage)
inlinenoexcept
Effects:
Creates it by passing it a static_allocator_storage by reference. It will take the address of the storage and use its memory for the allocation.
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.

Member Function Documentation

◆ allocate_node()

void * wpi::memory::static_allocator::allocate_node ( std::size_t size,
std::size_t alignment )
Effects:
A RawAllocator allocation function. It uses the specified static_allocator_storage.
Returns:
A pointer to a node, it will never be nullptr.
Throws:
An exception of type out_of_memory or whatever is thrown by its handler if the storage is exhausted.

◆ deallocate_node()

void wpi::memory::static_allocator::deallocate_node ( void * ,
std::size_t ,
std::size_t  )
inlinenoexcept
Effects:
A RawAllocator deallocation function. It does nothing, deallocation is not supported by this allocator.

◆ max_alignment()

std::size_t wpi::memory::static_allocator::max_alignment ( ) const
inlinenoexcept
Returns:
The maximum possible value since there is no alignment restriction (except indirectly through the size of the static_allocator_storage).

◆ max_node_size()

std::size_t wpi::memory::static_allocator::max_node_size ( ) const
inlinenoexcept
Returns:
The maximum node size which is the capacity remaining inside the static_allocator_storage.

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