MAGE  v0.171.0
Matthias Advanced Game Engine
mage::AlignedAllocator< T, A > Class Template Reference

#include <allocation.hpp>

Classes

struct  rebind
 

Public Types

using value_type = T
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using propagate_on_container_move_assignment = std::true_type
 
using is_always_equal = std::true_type
 

Public Member Functions

constexpr AlignedAllocator () noexcept=default
 
constexpr AlignedAllocator (const AlignedAllocator &allocator) noexcept=default
 
constexpr AlignedAllocator (AlignedAllocator &&allocator) noexcept=default
 
template<typename U >
constexpr AlignedAllocator ([[maybe_unused]] const AlignedAllocator< U, A > &allocator) noexcept
 
 ~AlignedAllocator ()=default
 
AlignedAllocatoroperator= (const AlignedAllocator &allocator) noexcept=default
 
AlignedAllocatoroperator= (AlignedAllocator &&allocator) noexcept=default
 
T * allocate (std::size_t count) const
 
T * allocate (std::size_t count, [[maybe_unused]] const void *hint) const
 
void deallocate (T *data, [[maybe_unused]] std::size_t count) const noexcept
 
template<typename U >
constexpr bool operator== ([[maybe_unused]] const AlignedAllocator< U, A > &rhs) const noexcept
 
template<typename U >
constexpr bool operator!= ([[maybe_unused]] const AlignedAllocator< U, A > &rhs) const noexcept
 

Detailed Description

template<typename T, std::size_t A = alignof(T)>
class mage::AlignedAllocator< T, A >

A class of aligned allocators.

Template Parameters
TThe data type.
AThe alignment in bytes.

Member Typedef Documentation

◆ difference_type

template<typename T , std::size_t A = alignof(T)>
using mage::AlignedAllocator< T, A >::difference_type = std::ptrdiff_t

◆ is_always_equal

template<typename T , std::size_t A = alignof(T)>
using mage::AlignedAllocator< T, A >::is_always_equal = std::true_type

◆ propagate_on_container_move_assignment

template<typename T , std::size_t A = alignof(T)>
using mage::AlignedAllocator< T, A >::propagate_on_container_move_assignment = std::true_type

◆ size_type

template<typename T , std::size_t A = alignof(T)>
using mage::AlignedAllocator< T, A >::size_type = std::size_t

◆ value_type

template<typename T , std::size_t A = alignof(T)>
using mage::AlignedAllocator< T, A >::value_type = T

Constructor & Destructor Documentation

◆ AlignedAllocator() [1/4]

template<typename T , std::size_t A = alignof(T)>
constexpr mage::AlignedAllocator< T, A >::AlignedAllocator ( )
defaultnoexcept

Constructs an aligned allocator.

◆ AlignedAllocator() [2/4]

template<typename T , std::size_t A = alignof(T)>
constexpr mage::AlignedAllocator< T, A >::AlignedAllocator ( const AlignedAllocator< T, A > &  allocator)
defaultnoexcept

Constructs an aligned allocator from the given aligned allocator.

Parameters
[in]allocatorA reference to the aligned allocator to copy.

◆ AlignedAllocator() [3/4]

template<typename T , std::size_t A = alignof(T)>
constexpr mage::AlignedAllocator< T, A >::AlignedAllocator ( AlignedAllocator< T, A > &&  allocator)
defaultnoexcept

Constructs an aligned allocator by moving the given aligned allocator.

Parameters
[in]allocatorA reference to the aligned allocator to move.

◆ AlignedAllocator() [4/4]

template<typename T , std::size_t A = alignof(T)>
template<typename U >
constexpr mage::AlignedAllocator< T, A >::AlignedAllocator ( [[maybe_unused] ] const AlignedAllocator< U, A > &  allocator)
noexcept

Constructs an aligned allocator from the given aligned allocator.

Template Parameters
UThe data type.
Parameters
[in]allocatorA reference to the aligned allocator to copy.

◆ ~AlignedAllocator()

template<typename T , std::size_t A = alignof(T)>
mage::AlignedAllocator< T, A >::~AlignedAllocator ( )
default

Destructs this aligned allocator.

Member Function Documentation

◆ allocate() [1/2]

template<typename T , std::size_t A = alignof(T)>
T* mage::AlignedAllocator< T, A >::allocate ( std::size_t  count) const

Allocates a block of storage with a size large enough to contain count elements of type T, and returns a pointer to the first element.

Parameters
[in]countThe number of objects of type T to allocate in memory.
Returns
A pointer to the memory block that was allocated. The pointer is a multiple of the alignment A.
Exceptions
std::bad_allocFailed to allocate the memory block.

◆ allocate() [2/2]

template<typename T , std::size_t A = alignof(T)>
T* mage::AlignedAllocator< T, A >::allocate ( std::size_t  count,
[[maybe_unused] ] const void *  hint 
) const

Allocates a block of storage with a size large enough to contain count elements of type T, and returns a pointer to the first element.

Parameters
[in]countThe number of objects of type T to allocate in memory.
[in]hintEither nullptr or a value previously obtained by another call to mage::AlignedAllocator<T,std::size_t>::allocate(std::size_t) and not yet freed with mage::AlignedAllocator<T,std::size_t>::deallocate(T*, std::size_t). When not equal to nullptr, this value may be used as a hint to improve performance by allocating the new block near the one specified. The address of an adjacent element is often a good choice.
Returns
A pointer to the memory block that was allocated. The pointer is a multiple of the alignment A.
Exceptions
std::bad_allocFailed to allocate the memory block.

◆ deallocate()

template<typename T , std::size_t A = alignof(T)>
void mage::AlignedAllocator< T, A >::deallocate ( T *  data,
[[maybe_unused] ] std::size_t  count 
) const
noexcept

Releases a block of storage previously allocated with mage::AlignedAllocator<T,std::size_t>::allocate(std::size_t) and not yet released.

Parameters
[in]dataA pointer to the memory block that needs to be released.
[in]countThe number of objects of type T allocated on the call to allocate this block of storage.
Note
The elements in the array are not destroyed.

◆ operator!=()

template<typename T , std::size_t A = alignof(T)>
template<typename U >
constexpr bool mage::AlignedAllocator< T, A >::operator!= ( [[maybe_unused] ] const AlignedAllocator< U, A > &  rhs) const
noexcept

Compares this aligned allocator to the given aligned allocator for non-equality.

Template Parameters
UThe data type.
Parameters
[in]rhsA reference to the aligned allocator to compare with.
Returns
true if and only if storage allocated from this aligned allocator cannot be deallocated from the given aligned allocator, and vice versa. This is never the case for stateless allocators. false otherwise.

◆ operator=() [1/2]

template<typename T , std::size_t A = alignof(T)>
AlignedAllocator& mage::AlignedAllocator< T, A >::operator= ( const AlignedAllocator< T, A > &  allocator)
defaultnoexcept

Copies the given aligned allocator to this aligned allocator.

Parameters
[in]allocatorA reference to the aligned allocator to copy.
Returns
A reference to the copy of the given aligned allocator (i.e. this aligned allocator).

◆ operator=() [2/2]

template<typename T , std::size_t A = alignof(T)>
AlignedAllocator& mage::AlignedAllocator< T, A >::operator= ( AlignedAllocator< T, A > &&  allocator)
defaultnoexcept

Moves the given aligned allocator to this aligned allocator.

Parameters
[in]allocatorA reference to the aligned allocator to move.
Returns
A reference to the moved aligned allocator (i.e. this aligned allocator).

◆ operator==()

template<typename T , std::size_t A = alignof(T)>
template<typename U >
constexpr bool mage::AlignedAllocator< T, A >::operator== ( [[maybe_unused] ] const AlignedAllocator< U, A > &  rhs) const
noexcept

Compares this aligned allocator to the given aligned allocator for equality.

Template Parameters
UThe data type.
Parameters
[in]rhsA reference to the aligned allocator to compare with.
Returns
true if and only if storage allocated from this aligned allocator can be deallocated from the given aligned allocator, and vice versa. This is always the case for stateless allocators. false otherwise.