19 void*
allocate(
size_t bytes_count)
final {
return std::malloc(bytes_count); }
32 template <
typename T, u
int64_t Alignment>
35 template <
typename, u
int64_t>
41 : m_alloc_impl((strategy !=
nullptr) ? strategy : mallocStrategy) {}
44 : m_alloc_impl(src.m_alloc_impl) {}
48 : m_alloc_impl(src.m_alloc_impl) {}
68 size_t buffer_size =
sizeof(T) * n + Alignment;
71 size_t alloc_size = buffer_size +
sizeof(
void*);
72 void* buffer = m_alloc_impl->allocate(alloc_size);
78 void* aligned_buffer =
static_cast<char*
>(buffer) +
sizeof(
void*);
79 std::align(Alignment,
sizeof(T) * n, aligned_buffer, buffer_size);
80 if (!aligned_buffer) {
85 void* store_buffer_addr =
86 static_cast<char*
>(aligned_buffer) -
sizeof(
void*);
87 *(
static_cast<void**
>(store_buffer_addr)) = buffer;
89 return static_cast<T*
>(aligned_buffer);
96 void* store_buffer_addr = (
reinterpret_cast<char*
>(p) -
sizeof(
void*));
97 void* free_address = *(
static_cast<void**
>(store_buffer_addr));
98 m_alloc_impl->deallocate(free_address, n);
106 template <
typename T>
bool operator!=(const AlignedAllocator &)
Definition: aligned-allocator.hpp:59
Allocates memory aligned to Alignment-byte sized boundaries.
Definition: aligned-allocator.hpp:33
Base class for custom memory allocator.
Definition: allocator.hpp:12
void * allocate(size_t bytes_count) final
Allocates byte_count bytes of memory.
Definition: aligned-allocator.hpp:19
std::shared_ptr< AllocatorBase > AllocatorStrategyPtr
Definition: aligned-allocator.hpp:27
std::vector< T, AlignedAllocator< T, 64 > > AlignedVector64
64-byte aligned memory allocator
Definition: aligned-allocator.hpp:107
T * allocate(size_t n)
Allocates n elements aligned to Alignment-byte boundaries.
Definition: aligned-allocator.hpp:63
~AlignedAllocator()
Definition: aligned-allocator.hpp:50
void deallocate(void *p, size_t n) final
Deallocate memory.
Definition: aligned-allocator.hpp:21
Allocater implementation using malloc and free.
Definition: aligned-allocator.hpp:18
bool IsPowerOfTwo(uint64_t num)
Returns whether or not num is a power of two.
Definition: number-theory.hpp:55
Definition: aligned-allocator.hpp:53
AlignedAllocator(AllocatorStrategyPtr strategy=nullptr) noexcept
Definition: aligned-allocator.hpp:40
Definition: eltwise-add-mod.hpp:8
void deallocate(T *p, size_t n)
Definition: aligned-allocator.hpp:92
uint64_t value_type
Definition: aligned-allocator.hpp:38
AlignedAllocator(const AlignedAllocator &src)
Definition: aligned-allocator.hpp:43
AllocatorStrategyPtr mallocStrategy
#define HEXL_UNUSED(x)
Definition: defines.hpp:13
AlignedAllocator(const AlignedAllocator< U, Alignment > &src)
Definition: aligned-allocator.hpp:47
bool operator==(const AlignedAllocator &)
Definition: aligned-allocator.hpp:57