Aligned memory allocator

template <class T, size_t Align>
class xsimd::aligned_allocator

Allocator for aligned memory.

The aligned_allocator class template is an allocator that performs memory allocation aligned by the specified value.

Template Parameters
  • T: type of objects to allocate.
  • Align: alignment in bytes.

Public Functions

aligned_allocator()

Default constructor.

aligned_allocator(const aligned_allocator &rhs)

Copy constructor.

template <class U>
aligned_allocator(const aligned_allocator<U, Align> &rhs)

Extended copy constructor.

~aligned_allocator()

Destructor.

auto address(reference r)

Returns the actual address of r even in presence of overloaded operator&.

Return
the actual address of r.
Parameters
  • r: the object to acquire address of.

auto address(const_reference r) const

Returns the actual address of r even in presence of overloaded operator&.

Return
the actual address of r.
Parameters
  • r: the object to acquire address of.

auto allocate(size_type n, typename std::allocator<void>::const_pointer hint = 0)

Allocates n * sizeof(T) bytes of uninitialized memory, aligned by A.

The alignment may require some extra memory allocation.

Return
a pointer to the first byte of a memory block suitably aligned and sufficient to hold an array of n objects of type T.
Parameters
  • n: the number of objects to allocate storage for.
  • hint: unused parameter provided for standard compliance.

void deallocate(pointer p, size_type n)

Deallocates the storage referenced by the pointer p, which must be a pointer obtained by an earlier call to allocate().

The argument n must be equal to the first argument of the call to allocate() that originally produced p; otherwise, the behavior is undefined.

Parameters

auto size_max() const

Returns the maximum theoretically possible value of \ n, for which the call allocate(n, 0) could succeed.

Return
themaximum supported allocated size.

template <class U, class… Args>
void construct(U *p, Args&&... args)

Constructs an object of type \ T in allocated uninitialized memory pointed to by \ p, using placement-new.

Parameters
  • p: pointer to allocated uninitialized memory.
  • args: the constructor arguments to use.

template <class U>
void destroy(U *p)

Calls the destructor of the object pointed to by p.

Parameters
  • p: pointer to the object that is going to be destroyed.

Comparison operators

template <class T1, size_t A1, class T2, size_t A2>
bool xsimd::operator==(const aligned_allocator<T1, A1> &lhs, const aligned_allocator<T2, A2> &rhs)

Compares two aligned memory allocator for equality.

Since allocators are stateless, return true iff A1 == A2.

Return
true if the allocators have the same alignment.
Parameters

template <class T1, size_t A1, class T2, size_t A2>
bool xsimd::operator!=(const aligned_allocator<T1, A1> &lhs, const aligned_allocator<T2, A2> &rhs)

Compares two aligned memory allocator for inequality.

Since allocators are stateless, return true iff A1 != A2.

Return
true if the allocators have different alignments.
Parameters