26template <
typename ElementType,
size_t alignmentInBytes>
27requires (alignmentInBytes >=
alignof (ElementType) && is::powerOfTwoInt<alignmentInBytes>)
31 using value_type = ElementType;
32 using size_type = std::size_t;
36 template <
class OtherElementType>
39 [[nodiscard]] ElementType* allocate (
size_t nElementsToAllocate)
41 if (nElementsToAllocate > std::numeric_limits<size_t>::max() /
sizeof (ElementType))
43 throw std::bad_array_new_length();
46 const auto nBytesToAllocate = detail::nextMultipleOf<Config::maxSIMDRegisterSize> (nElementsToAllocate *
sizeof (ElementType));
51 return reinterpret_cast<ElementType*
> (::operator
new[] (nBytesToAllocate, std::align_val_t (alignmentInBytes)));
54 auto status = posix_memalign (&ptr, alignmentInBytes, nBytesToAllocate);
56 throw std::bad_alloc();
57 return reinterpret_cast<ElementType*
> (ptr);
61 void deallocate (ElementType* allocatedPointer, [[maybe_unused]]
size_t nBytesAllocated)
64 ::operator
delete[] (allocatedPointer, std::align_val_t (alignmentInBytes));
66 free (allocatedPointer);
77template <
class ElementType,
size_t alignmentInBytesLHS,
size_t alignmentInBytesRHS>
80 return alignmentInBytesLHS == alignmentInBytesRHS;
Returns aligned pointers when allocations are requested.
Definition: AlignedAllocator.h:29
The main namespace of the VCTR project.
Definition: Array.h:24
constexpr bool operator==(const Lhs &lhs, const Rhs &rhs)
Compares lhs and rhs for equality.
Definition: VctrBase.h:1162
Definition: AlignedAllocator.h:72