Template Class AlignedAllocator

Class Documentation

template<class T>
class AlignedAllocator

C++ Allocator class for aligned memory.

C++17’s std::pmr::polymorphic_allocator substitutes this whole class. However, clang (even the latest version 13) does not support pmr yet.

Template Parameters

T – Datatype to allocate

Public Types

using value_type = T

Public Functions

inline explicit constexpr AlignedAllocator(uint32_t alignment)

Constructor of AlignedAllocator class.

Parameters

alignment – Memory alignment we want.

inline uint32_t alignment() const

Get alignment of the allocator.

template<typename U>
inline explicit constexpr AlignedAllocator([[maybe_unused]] const AlignedAllocator<U> &rhs) noexcept
inline T *allocate(std::size_t size) const

Allocate memory with for the given number of datatype T.

Parameters

size – The number of T objects for the allocation

Returns

Allocated aligned memory

inline void deallocate(T *p, [[maybe_unused]] std::size_t size) const noexcept

Deallocate allocated memory.

Parameters
  • p – Pointer to the allocated data

  • size – Size of the data we allocated (unused).

template<class U>
inline void construct(U *ptr)
template<class U>
inline void destroy(U *ptr)