WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::fallback_allocator< Default, Fallback > Class Template Reference

A RawAllocator with a fallback. More...

#include <wpi/memory/fallback_allocator.hpp>

Public Types

using default_allocator_type = typename allocator_traits<Default>::allocator_type
 
using fallback_allocator_type = typename allocator_traits<Fallback>::allocator_type
 
using is_stateful
 

Public Member Functions

 fallback_allocator ()
 
 fallback_allocator (default_allocator_type &&default_alloc, fallback_allocator_type &&fallback_alloc={})
 
void * allocate_node (std::size_t size, std::size_t alignment)
 
void * allocate_array (std::size_t count, std::size_t size, std::size_t alignment)
 
void deallocate_node (void *ptr, std::size_t size, std::size_t alignment) noexcept
 
void deallocate_array (void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
void * try_allocate_node (std::size_t size, std::size_t alignment) noexcept
 
void * allocate_array (std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
bool try_deallocate_node (void *ptr, std::size_t size, std::size_t alignment) noexcept
 
bool try_deallocate_array (void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
std::size_t max_node_size () const
 
std::size_t max_array_size () const
 
std::size_t max_alignment () const
 
default_allocator_typeget_default_allocator () noexcept
 
const default_allocator_typeget_default_allocator () const noexcept
 
fallback_allocator_typeget_fallback_allocator () noexcept
 
const fallback_allocator_typeget_fallback_allocator () const noexcept
 

Detailed Description

template<class Default, class Fallback>
class wpi::memory::fallback_allocator< Default, Fallback >

A RawAllocator with a fallback.

Allocation first tries Default, if it fails, it uses Fallback.

Requires:
Default must be a composable RawAllocator, Fallback must be a RawAllocator.

Member Typedef Documentation

◆ default_allocator_type

template<class Default , class Fallback >
using wpi::memory::fallback_allocator< Default, Fallback >::default_allocator_type = typename allocator_traits<Default>::allocator_type

◆ fallback_allocator_type

template<class Default , class Fallback >
using wpi::memory::fallback_allocator< Default, Fallback >::fallback_allocator_type = typename allocator_traits<Fallback>::allocator_type

◆ is_stateful

template<class Default , class Fallback >
using wpi::memory::fallback_allocator< Default, Fallback >::is_stateful
Initial value:
std::integral_constant<bool, default_traits::is_stateful::value
|| fallback_traits::is_stateful::value>

Constructor & Destructor Documentation

◆ fallback_allocator() [1/2]

template<class Default , class Fallback >
wpi::memory::fallback_allocator< Default, Fallback >::fallback_allocator ( )
inline
Effects:
Default constructs both allocators.
Notes:
This function only participates in overload resolution, if both allocators are not stateful.

◆ fallback_allocator() [2/2]

template<class Default , class Fallback >
wpi::memory::fallback_allocator< Default, Fallback >::fallback_allocator ( default_allocator_type && default_alloc,
fallback_allocator_type && fallback_alloc = {} )
inlineexplicit
Effects:
Constructs the allocator by passing in the two allocators it has.

Member Function Documentation

◆ allocate_array() [1/2]

template<class Default , class Fallback >
void * wpi::memory::fallback_allocator< Default, Fallback >::allocate_array ( std::size_t count,
std::size_t size,
std::size_t alignment )
inline

◆ allocate_array() [2/2]

template<class Default , class Fallback >
void * wpi::memory::fallback_allocator< Default, Fallback >::allocate_array ( std::size_t count,
std::size_t size,
std::size_t alignment )
inlinenoexcept

◆ allocate_node()

template<class Default , class Fallback >
void * wpi::memory::fallback_allocator< Default, Fallback >::allocate_node ( std::size_t size,
std::size_t alignment )
inline
Effects:
First calls the compositioning (de)allocation function on the default_allocator_type. If that fails, uses the non-compositioning function of the fallback_allocator_type.

◆ deallocate_array()

template<class Default , class Fallback >
void wpi::memory::fallback_allocator< Default, Fallback >::deallocate_array ( void * ptr,
std::size_t count,
std::size_t size,
std::size_t alignment )
inlinenoexcept

◆ deallocate_node()

template<class Default , class Fallback >
void wpi::memory::fallback_allocator< Default, Fallback >::deallocate_node ( void * ptr,
std::size_t size,
std::size_t alignment )
inlinenoexcept

◆ get_default_allocator() [1/2]

template<class Default , class Fallback >
const default_allocator_type & wpi::memory::fallback_allocator< Default, Fallback >::get_default_allocator ( ) const
inlinenoexcept

◆ get_default_allocator() [2/2]

template<class Default , class Fallback >
default_allocator_type & wpi::memory::fallback_allocator< Default, Fallback >::get_default_allocator ( )
inlinenoexcept
Returns:
A (const) reference to the default allocator.

◆ get_fallback_allocator() [1/2]

template<class Default , class Fallback >
const fallback_allocator_type & wpi::memory::fallback_allocator< Default, Fallback >::get_fallback_allocator ( ) const
inlinenoexcept

◆ get_fallback_allocator() [2/2]

template<class Default , class Fallback >
fallback_allocator_type & wpi::memory::fallback_allocator< Default, Fallback >::get_fallback_allocator ( )
inlinenoexcept
Returns:
A (const) reference to the fallback allocator.

◆ max_alignment()

template<class Default , class Fallback >
std::size_t wpi::memory::fallback_allocator< Default, Fallback >::max_alignment ( ) const
inline

◆ max_array_size()

template<class Default , class Fallback >
std::size_t wpi::memory::fallback_allocator< Default, Fallback >::max_array_size ( ) const
inline

◆ max_node_size()

template<class Default , class Fallback >
std::size_t wpi::memory::fallback_allocator< Default, Fallback >::max_node_size ( ) const
inline
Returns:
The maximum of the two values from both allocators.

◆ try_allocate_node()

template<class Default , class Fallback >
void * wpi::memory::fallback_allocator< Default, Fallback >::try_allocate_node ( std::size_t size,
std::size_t alignment )
inlinenoexcept
Effects:
First calls the compositioning (de)allocation function on the default_allocator_type. If that fails, uses the compositioning function of the fallback_allocator_type.
Requires:
The fallback_allocator_type msut be composable.

◆ try_deallocate_array()

template<class Default , class Fallback >
bool wpi::memory::fallback_allocator< Default, Fallback >::try_deallocate_array ( void * ptr,
std::size_t count,
std::size_t size,
std::size_t alignment )
inlinenoexcept

◆ try_deallocate_node()

template<class Default , class Fallback >
bool wpi::memory::fallback_allocator< Default, Fallback >::try_deallocate_node ( void * ptr,
std::size_t size,
std::size_t alignment )
inlinenoexcept

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