37#ifndef AlignedAllocator_h
38#define AlignedAllocator_h
51template <
class T,
size_t alignment>
105 {
return (
static_cast<size_t>(0) -
static_cast<size_t>(1)) /
sizeof(T); }
120 {
return !(*
this == other); }
130 {
new(
static_cast<void*
>(p) ) T(t); }
132 void destroy(T*
const p)
const
165 throw std::length_error(
"AlignedAllocator<T>::allocate(): requested size is too large, integer overflow?");
168 if( (n % alignment) != 0)
170 n |= (alignment - 1);
176 T* ret =
static_cast<T*
>(_aligned_malloc(n*
sizeof(T), alignment));
178 T* ret =
static_cast<T*
>(aligned_alloc(alignment, n*
sizeof(T)));
183 throw std::bad_alloc();
194 void deallocate(T*
const p, [[maybe_unused]]
const size_t unused)
const
219 T*
allocate(
const size_t n, [[maybe_unused]]
const U*
const hint)
Aligned memory allocator for STL containers.
Definition: AlignedAllocator.h:53
size_t size_type
Type of the size of an allocated object.
Definition: AlignedAllocator.h:72
const T & const_reference
Const reference to the allocated type.
Definition: AlignedAllocator.h:66
T * allocate(const size_t n, const U *const hint)
Allocate an object.
Definition: AlignedAllocator.h:219
ptrdiff_t difference_type
Type of the difference between two allocated pointers.
Definition: AlignedAllocator.h:75
const T * address(T &rhs) const
Get the address of an object.
Definition: AlignedAllocator.h:96
void deallocate(T *const p, const size_t unused) const
Free a block of memory.
Definition: AlignedAllocator.h:194
T * address(T &rhs)
Get the address of an object.
Definition: AlignedAllocator.h:85
T * allocate(size_t n) const
Allocate a block of memory.
Definition: AlignedAllocator.h:159
void construct(T *const p, const T &t) const
Construct an object in-place given a reference one.
Definition: AlignedAllocator.h:129
T value_type
The allocated type.
Definition: AlignedAllocator.h:69
bool operator!=(const AlignedAllocator &other) const
Check if two allocators are the same.
Definition: AlignedAllocator.h:119
const T * const_pointer
Const pointer to the allocated type.
Definition: AlignedAllocator.h:60
T & reference
Reference to the allocated type.
Definition: AlignedAllocator.h:63
T * pointer
Pointer to the allocated type.
Definition: AlignedAllocator.h:57
size_t max_size() const
Get the max possible allocation size the allocator supports.
Definition: AlignedAllocator.h:104
void deallocate(T *const p) const
Free a single object.
Definition: AlignedAllocator.h:208
Rebind to a different type of allocator.
Definition: AlignedAllocator.h:110