12#ifndef XSIMD_ALIGNED_ALLOCATOR_HPP
13#define XSIMD_ALIGNED_ALLOCATOR_HPP
31 #define XSIMD_INLINE inline __attribute__((always_inline))
32 #elif defined(_MSC_VER)
33 #define XSIMD_INLINE inline __forceinline
35 #define XSIMD_INLINE inline
48 template <
class T,
size_t Align = 64>
85 template <class U, class... Args>
92 template <class T1,
size_t Align1, class T2,
size_t Align2>
96 template <class T1,
size_t Align1, class T2,
size_t Align2>
113 template <class T,
size_t A>
121 template <
class T,
size_t A>
129 template <
class T,
size_t A>
138 template <
class T,
size_t A>
148 template <
class T,
size_t A>
160 template <
class T,
size_t A>
175 template <
class T,
size_t A>
180#if defined(_CPPUNWIND) || defined(__cpp_exceptions)
182 throw std::bad_alloc();
194 template <
class T,
size_t A>
205 template <
class T,
size_t A>
215 template <
class T,
size_t A>
228 template <
class T,
size_t A>
229 template <
class U,
class... Args>
232 new (
static_cast<void*
>(p)) U(std::forward<Args>(args)...);
239 template <
class T,
size_t A>
258 template <
class T1,
size_t A1,
class T2,
size_t A2>
262 return lhs.alignment == rhs.alignment;
273 template <
class T1,
size_t A1,
class T2,
size_t A2>
277 return !(lhs == rhs);
288 assert(((alignment & (alignment - 1)) == 0) &&
"alignment must be a power of two");
289 assert((alignment >=
sizeof(
void*)) &&
"alignment must be at least the size of a pointer");
292 res = _aligned_malloc(size, alignment);
294 if (posix_memalign(&res, alignment, size) != 0)
333 else if (
size_t(p) & (
sizeof(T) - 1))
342 size_t block_mask = block_size - 1;
343 return std::min<size_t>(
344 (block_size - ((
size_t(p) /
sizeof(T)) & block_mask)) & block_mask,
Allocator for aligned memory.
XSIMD_INLINE ~aligned_allocator()
Destructor.
XSIMD_INLINE void construct(U *p, Args &&... args)
XSIMD_INLINE void deallocate(pointer p, size_type n)
XSIMD_INLINE size_type max_size() const noexcept
ptrdiff_t difference_type
static constexpr size_t alignment
XSIMD_INLINE pointer allocate(size_type n, const void *hint=0)
const T & const_reference
XSIMD_INLINE void destroy(U *p)
XSIMD_INLINE aligned_allocator() noexcept
Default constructor.
XSIMD_INLINE size_type size_max() const noexcept
XSIMD_INLINE pointer address(reference) noexcept
XSIMD_INLINE void xaligned_free(void *ptr)
XSIMD_INLINE void * xaligned_malloc(size_t size, size_t alignment)
XSIMD_INLINE bool operator==(const aligned_allocator< T1, Align1 > &lhs, const aligned_allocator< T2, Align2 > &rhs) noexcept
XSIMD_INLINE bool operator!=(const aligned_allocator< T1, Align1 > &lhs, const aligned_allocator< T2, Align2 > &rhs) noexcept
XSIMD_INLINE void aligned_free(void *ptr)
XSIMD_INLINE size_t get_alignment_offset(const T *p, size_t size, size_t block_size)
XSIMD_INLINE void * aligned_malloc(size_t size, size_t alignment)
aligned_allocator< U, Align > other