bit::memory
Public Member Functions | List of all members
bit::memory::fallback_allocator< AllocatorStorages > Class Template Reference

This allocator acts as an aggregate that can fall back to other allocators on failure. More...

#include <fallback_allocator.hpp>

Inheritance diagram for bit::memory::fallback_allocator< AllocatorStorages >:
bit::memory::ebo_storage< AllocatorStorages... >

Public Member Functions

 fallback_allocator (AllocatorStorages...storages) noexcept
 Constructs each allocator in the fallback_allocator in-place, constructing each allocator from a single argument. More...
 
 fallback_allocator (fallback_allocator &&other)=default
 Move-constructs the fallback_allocator from an existing one. More...
 
 fallback_allocator (const fallback_allocator &other)=default
 Copy-constructs the fallback_allocator from an existing one. More...
 
fallback_allocatoroperator= (fallback_allocator &&other)=default
 Move-assigns the fallback_allocator from an existing one. More...
 
fallback_allocatoroperator= (const fallback_allocator &other)=default
 Copy-assigns the fallback_allocator from an existing one. More...
 
owner< void * > try_allocate (std::size_t size, std::size_t align) noexcept
 Attempts to allocate memory, starting with the first allocator in sequence, and falling back to further allocators on failure. More...
 
void deallocate (owner< void *> p, std::size_t size)
 Deallocates the pointer p of size size from the underlying allocator. More...
 
bool owns (const void *p) const noexcept
 Checks if any of the allocators in the fallback allocator owns the memory pointer to by p. More...
 
std::size_t max_size () const noexcept
 Determines the maximum size of the allocations that this fallback_allocator supports. More...
 
std::size_t min_size () const noexcept
 Determines the minimum size of the allocations that this fallback_allocator supports. More...
 

Detailed Description

template<typename... AllocatorStorages>
class bit::memory::fallback_allocator< AllocatorStorages >

This allocator acts as an aggregate that can fall back to other allocators on failure.

This will attempt to allocate memory from the first allocator in the sequence, and – on failure – will fall-back to the next one in sequence.

For deallocations, all allocators except the last one must implement the 'owns' member function to identify ownership of previously allocated memory. The last allocator in the sequence is a special-case that doesn't require ownership, allowing for raw allocators to be used as the final fallback in the allocation sequence.

Satisfies
Allocator
Template Parameters
AllocatorStoragesthe allocator storages to sequence through

Definition at line 73 of file fallback_allocator.hpp.

Constructor & Destructor Documentation

◆ fallback_allocator() [1/3]

template<typename... AllocatorStorages>
bit::memory::fallback_allocator< AllocatorStorages >::fallback_allocator ( AllocatorStorages...  storages)
explicitnoexcept

Constructs each allocator in the fallback_allocator in-place, constructing each allocator from a single argument.

Parameters
storagesthe allocator storage types to use

◆ fallback_allocator() [2/3]

template<typename... AllocatorStorages>
bit::memory::fallback_allocator< AllocatorStorages >::fallback_allocator ( fallback_allocator< AllocatorStorages > &&  other)
default

Move-constructs the fallback_allocator from an existing one.

Note
This constructor is only enabled if all allocators are move- constructible
Parameters
otherthe other fallback_allocator to move

◆ fallback_allocator() [3/3]

template<typename... AllocatorStorages>
bit::memory::fallback_allocator< AllocatorStorages >::fallback_allocator ( const fallback_allocator< AllocatorStorages > &  other)
default

Copy-constructs the fallback_allocator from an existing one.

Note
This constructor is only enabled if all allocators are copy- constructible
Parameters
otherthe other fallback_allocator to copy

Member Function Documentation

◆ deallocate()

template<typename... AllocatorStorages>
void bit::memory::fallback_allocator< AllocatorStorages >::deallocate ( owner< void *>  p,
std::size_t  size 
)

Deallocates the pointer p of size size from the underlying allocator.

Bug:
If two allocators inside of this fallback allocator both allocate within the same memory region (e.g. inside the same memory block), then the origin of p may be incorrectly determined and deallocated incorrectly.
Parameters
pthe pointer to memory to deallocate
sizethe size of the memory to deallocate

◆ max_size()

template<typename... AllocatorStorages>
std::size_t bit::memory::fallback_allocator< AllocatorStorages >::max_size ( ) const
noexcept

Determines the maximum size of the allocations that this fallback_allocator supports.

Returns
the max size

◆ min_size()

template<typename... AllocatorStorages>
std::size_t bit::memory::fallback_allocator< AllocatorStorages >::min_size ( ) const
noexcept

Determines the minimum size of the allocations that this fallback_allocator supports.

Returns
the min size

◆ operator=() [1/2]

template<typename... AllocatorStorages>
fallback_allocator& bit::memory::fallback_allocator< AllocatorStorages >::operator= ( fallback_allocator< AllocatorStorages > &&  other)
default

Move-assigns the fallback_allocator from an existing one.

Note
This operator is only enabled if all allocators are copy- assignable
Parameters
otherthe other fallback_allocator to move

◆ operator=() [2/2]

template<typename... AllocatorStorages>
fallback_allocator& bit::memory::fallback_allocator< AllocatorStorages >::operator= ( const fallback_allocator< AllocatorStorages > &  other)
default

Copy-assigns the fallback_allocator from an existing one.

Note
This operator is only enabled if all allocators are copy- assignable
Parameters
otherthe other fallback_allocator to copy

◆ owns()

template<typename... AllocatorStorages>
bool bit::memory::fallback_allocator< AllocatorStorages >::owns ( const void *  p) const
noexcept

Checks if any of the allocators in the fallback allocator owns the memory pointer to by p.

Parameters
pthe pointer to check
Returns
true if the memory is owned by an allocator in this allocator

◆ try_allocate()

template<typename... AllocatorStorages>
owner<void*> bit::memory::fallback_allocator< AllocatorStorages >::try_allocate ( std::size_t  size,
std::size_t  align 
)
noexcept

Attempts to allocate memory, starting with the first allocator in sequence, and falling back to further allocators on failure.

Parameters
sizethe size of the allocation request
alignthe alignment of the allocation request
Returns
a pointer on success, nullptr on failure

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