memory
Typedefs | Member Functions | Related Functions
aligned_allocator< RawAllocator > Class Template Reference

Detailed Description

template<class RawAllocator>
class foonathan::memory::aligned_allocator< RawAllocator >

A RawAllocator adapter that ensures a minimum alignment.

It adjusts the alignment value so that it is always larger than the minimum and forwards to the specified allocator.

Typedefs

using allocator_type = typename allocator_traits< RawAllocator >::allocator_type
 
using is_stateful = std::true_type
 

Member Functions

 aligned_allocator (std::size_t min_alignment, allocator_type &&alloc={})
 
std::size_t min_alignment () const noexcept
 
void set_min_alignment (std::size_t min_alignment)
 
 aligned_allocator (aligned_allocator &&other) noexcept
 
aligned_allocatoroperator= (aligned_allocator &&other) noexcept
 
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 * try_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
 
allocator_type & get_allocator () noexcept
 
const allocator_type & get_allocator () const noexcept
 

Related Functions

template<class RawAllocator >
auto make_aligned_allocator (std::size_t min_alignment, RawAllocator &&allocator) noexcept -> aligned_allocator< typename std::decay< RawAllocator >::type >
 

Constructors

◆ aligned_allocator() [1/2]

aligned_allocator ( std::size_t  min_alignment,
allocator_type &&  alloc = {} 
)
explicit
Effects:
Creates it passing it the minimum alignment value and the allocator object.
Requires:
min_alignment must be less than this->max_alignment().

◆ aligned_allocator() [2/2]

aligned_allocator ( aligned_allocator< RawAllocator > &&  other)
noexcept
Effects:
Moves the aligned_allocator object. It simply moves the underlying allocator.

Member Functions

◆ operator=()

aligned_allocator & operator= ( aligned_allocator< RawAllocator > &&  other)
noexcept
Effects:
Moves the aligned_allocator object. It simply moves the underlying allocator.

◆ allocate_node()

void * allocate_node ( std::size_t  size,
std::size_t  alignment 
)
Effects:
Forwards to the underlying allocator through the allocator_traits. If the alignment is less than the min_alignment(), it is set to the minimum alignment.

◆ allocate_array()

void * allocate_array ( std::size_t  count,
std::size_t  size,
std::size_t  alignment 
)
Effects:
Forwards to the underlying allocator through the allocator_traits. If the alignment is less than the min_alignment(), it is set to the minimum alignment.

◆ deallocate_node()

void deallocate_node ( void *  ptr,
std::size_t  size,
std::size_t  alignment 
)
noexcept
Effects:
Forwards to the underlying allocator through the allocator_traits. If the alignment is less than the min_alignment(), it is set to the minimum alignment.

◆ deallocate_array()

void deallocate_array ( void *  ptr,
std::size_t  count,
std::size_t  size,
std::size_t  alignment 
)
noexcept
Effects:
Forwards to the underlying allocator through the allocator_traits. If the alignment is less than the min_alignment(), it is set to the minimum alignment.

◆ try_allocate_node()

void * try_allocate_node ( std::size_t  size,
std::size_t  alignment 
)
noexcept
Effects:
Forwards to the underlying allocator through the composable_allocator_traits. If the alignment is less than the min_alignment(), it is set to the minimum alignment.
Requires:
The underyling allocator must be composable.

◆ try_allocate_array()

void * try_allocate_array ( std::size_t  count,
std::size_t  size,
std::size_t  alignment 
)
noexcept
Effects:
Forwards to the underlying allocator through the composable_allocator_traits. If the alignment is less than the min_alignment(), it is set to the minimum alignment.
Requires:
The underyling allocator must be composable.

◆ try_deallocate_node()

bool try_deallocate_node ( void *  ptr,
std::size_t  size,
std::size_t  alignment 
)
noexcept
Effects:
Forwards to the underlying allocator through the composable_allocator_traits. If the alignment is less than the min_alignment(), it is set to the minimum alignment.
Requires:
The underyling allocator must 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:
Forwards to the underlying allocator through the composable_allocator_traits. If the alignment is less than the min_alignment(), it is set to the minimum alignment.
Requires:
The underyling allocator must be composable.

◆ max_node_size()

std::size_t max_node_size ( ) const
Returns:
The value returned by the allocator_traits for the underlying allocator.

◆ max_array_size()

std::size_t max_array_size ( ) const
Returns:
The value returned by the allocator_traits for the underlying allocator.

◆ max_alignment()

std::size_t max_alignment ( ) const
Returns:
The value returned by the allocator_traits for the underlying allocator.

◆ get_allocator() [1/2]

allocator_type & get_allocator ( )
noexcept
Returns:
A reference to the underlying allocator.

◆ get_allocator() [2/2]

const allocator_type & get_allocator ( ) const
noexcept
Returns:
A reference to the underlying allocator.

◆ min_alignment()

std::size_t min_alignment ( ) const
noexcept
Returns:
The minimum alignment.

◆ set_min_alignment()

void set_min_alignment ( std::size_t  min_alignment)
Effects:
Sets the minimum alignment to a new value.
Requires:
min_alignment must be less than this->max_alignment().

Related Functions

◆ make_aligned_allocator()

auto make_aligned_allocator ( std::size_t  min_alignment,
RawAllocator &&  allocator 
) -> aligned_allocator<typename std::decay<RawAllocator>::type>
related
Returns:
A new aligned_allocator created by forwarding the parameters to the constructor.