34 concept
is_mangle_able = std::same_as<std::decay_t<T>,
float> || std::same_as<std::decay_t<T>,
double>
35 || cpp::specialization_of<std::complex, T> || cpp::specialization_of<etl::complex, T>;
48 template <
typename T,
size_t S = sizeof(T)>
50 auto required_bytes =
sizeof(T) * size;
51 auto offset = (A - 1) +
sizeof(uintptr_t);
52 auto orig = malloc(required_bytes + offset);
58 auto aligned =
reinterpret_cast<void**
>((
reinterpret_cast<size_t>(orig) + offset) & ~(A - 1));
60 return reinterpret_cast<T*
>(
aligned);
67 template <
typename T,
size_t S = sizeof(T)>
70 free((reinterpret_cast<void**>(
const_cast<std::remove_const_t<T>*
>(ptr)))[-1]);
79 template <
typename T,
size_t S = sizeof(T)>
81 static_assert(is_mangle_able<T>,
"allocate does not work with vector types");
82 return std::make_unique<T[]>(size);
90 template <
typename T,
size_t S = sizeof(T)>
99 template <
typename T,
size_t S = sizeof(T)>
107 template <
typename T,
size_t S = sizeof(T)>
177 template <
typename T,
size_t S = sizeof(T)>
T & operator[](size_t i)
Returns a reference to the element at psition i.
Definition: allocator.hpp:144
aligned_ptr(T *ptr)
Build an aligned_ptr managing the given pointer.
Definition: allocator.hpp:114
aligned_ptr(aligned_ptr &&rhs) noexcept
Move construct an aligned_ptr.
Definition: allocator.hpp:123
void aligned_release(T *ptr, mangling_faker< S >=mangling_faker< S >())
Release some aligned memory.
Definition: allocator.hpp:100
static void release(T *ptr, mangling_faker< S >=mangling_faker< S >())
Release the memory.
Definition: allocator.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
constexpr bool aligned
Alignment flag to aligned expressions.
Definition: std.hpp:46
const T & operator[](size_t i) const
Returns a reference to the element at psition i.
Definition: allocator.hpp:151
Allocated for aligned memory.
Definition: allocator.hpp:42
T * ptr
The raw pointer.
Definition: allocator.hpp:109
Use of this type in the parameter with the size of a vector type fakes mangling.
Definition: allocator.hpp:27
aligned_ptr & operator=(aligned_ptr &&rhs) noexcept
Move assign an aligned_ptr.
Definition: allocator.hpp:132
T * aligned_allocate(size_t size, mangling_faker< S >=mangling_faker< S >())
Allocate an aligned rray of the given size for the given type.
Definition: allocator.hpp:91
~aligned_ptr()
Destruct the aligned_ptr and release the aligned memory.
Definition: allocator.hpp:158
aligned_ptr< T > aligned_allocate_auto(size_t size, mangling_faker< S >=mangling_faker< S >())
Allocate an aligned rray of the given size for the given type.
Definition: allocator.hpp:178
static T * allocate(size_t size, mangling_faker< S >=mangling_faker< S >())
Allocate a block of memory of size elements.
Definition: allocator.hpp:49
RAII wrapper for allocated aligned memory.
Definition: allocator.hpp:108
auto allocate(size_t size, mangling_faker< S >=mangling_faker< S >())
Allocate an array of the given size for the given type.
Definition: allocator.hpp:80
concept is_mangle_able
Test if the given type can be mangled correctly.
Definition: allocator.hpp:34