Documentation of memory

( foonathan/memory)

fallback_allocator< Default, Fallback > Class Template Reference

Detailed Description

template<class Default, class Fallback>
class foonathan::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.

Typedefs

using default_allocator_type = typename allocator_traits< Default >::allocator_type
 
using fallback_allocator_type = typename allocator_traits< Fallback >::allocator_type
 
using is_stateful = std::integral_constant< bool, default_traits::is_stateful::value||fallback_traits::is_stateful::value >
 

Member Functions

 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
 
template<typename Dummy = std::true_type>
void * try_allocate_node (std::size_t size, std::size_t alignment) noexcept
 
template<typename Dummy = std::true_type>
void * allocate_array (std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
template<typename Dummy = std::true_type>
bool try_deallocate_node (void *ptr, std::size_t size, std::size_t alignment) noexcept
 
template<typename Dummy = std::true_type>
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_type & get_default_allocator () noexcept
 
const default_allocator_type & get_default_allocator () const noexcept
 
fallback_allocator_type & get_fallback_allocator () noexcept
 
const fallback_allocator_type & get_fallback_allocator () const noexcept
 

Constructors

§ fallback_allocator()

fallback_allocator ( default_allocator_type &&  default_alloc,
fallback_allocator_type &&  fallback_alloc = {} 
)
explicit
Effects:
Constructs the allocator by passing in the two allocators it has.

Member Functions

§ allocate_node()

void* allocate_node ( std::size_t  size,
std::size_t  alignment 
)
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.

§ allocate_array() [1/2]

void* allocate_array ( std::size_t  count,
std::size_t  size,
std::size_t  alignment 
)
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_node()

void deallocate_node ( void *  ptr,
std::size_t  size,
std::size_t  alignment 
)
noexcept
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()

void deallocate_array ( void *  ptr,
std::size_t  count,
std::size_t  size,
std::size_t  alignment 
)
noexcept
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.

§ try_allocate_node()

void* try_allocate_node ( std::size_t  size,
std::size_t  alignment 
)
noexcept
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.

§ allocate_array() [2/2]

void* allocate_array ( std::size_t  count,
std::size_t  size,
std::size_t  alignment 
)
noexcept
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_node()

bool try_deallocate_node ( void *  ptr,
std::size_t  size,
std::size_t  alignment 
)
noexcept
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()

bool try_deallocate_array ( void *  ptr,
std::size_t  count,
std::size_t  size,
std::size_t  alignment 
)
noexcept
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.

§ max_node_size()

std::size_t max_node_size ( ) const
Returns:
The maximum of the two values from both allocators.

§ max_array_size()

std::size_t max_array_size ( ) const
Returns:
The maximum of the two values from both allocators.

§ max_alignment()

std::size_t max_alignment ( ) const
Returns:
The maximum of the two values from both allocators.

§ get_default_allocator() [1/2]

default_allocator_type& get_default_allocator ( )
noexcept
Returns:
A (const) reference to the default allocator.

§ get_default_allocator() [2/2]

const default_allocator_type& get_default_allocator ( ) const
noexcept
Returns:
A (const) reference to the default allocator.

§ get_fallback_allocator() [1/2]

fallback_allocator_type& get_fallback_allocator ( )
noexcept
Returns:
A (const) reference to the fallback allocator.

§ get_fallback_allocator() [2/2]

const fallback_allocator_type& get_fallback_allocator ( ) const
noexcept
Returns:
A (const) reference to the fallback allocator.