28template <
class T,
size_t Alignment = DEFAULT_CACHE_LINE_SIZE>
78 size_t max_size() const noexcept {
return (std::numeric_limits<size_t>::max() -
size_t(Alignment)) /
sizeof(T); }
87 size_t neededSize =
sizeof(T) * n;
89 static_assert(Alignment > 0,
"Alignment must be bigger than 0!");
91 size_t sizeToRequest = ((neededSize + Alignment - 1) / Alignment) * Alignment;
92 T *ptr =
static_cast<T *
>(aligned_alloc(Alignment, sizeToRequest));
94 throw std::bad_alloc();
98 throw std::bad_alloc();
113 template <
class U,
class... Args>
115 ::new ((
void *)p) U(std::forward<Args>(args)...);
136template <
typename T,
size_t TAlignment,
typename U,
size_t UAlignment>
138 return TAlignment == UAlignment;
151template <
typename T,
size_t TAlignment,
typename U,
size_t UAlignment>
AlignedAllocator class.
Definition: AlignedAllocator.h:29
T * pointer
pointer type
Definition: AlignedAllocator.h:35
T * allocate(std::size_t n)
Allocate aligned memory for n objects of type T.
Definition: AlignedAllocator.h:85
T & reference
reference type
Definition: AlignedAllocator.h:39
size_t size_type
size type
Definition: AlignedAllocator.h:43
~AlignedAllocator()=default
Default destructor.
T value_type
value type
Definition: AlignedAllocator.h:33
const T & const_reference
const reference type
Definition: AlignedAllocator.h:41
void construct(U *p, Args &&...args)
Construct object of type U at already allocated memory, pointed to by p.
Definition: AlignedAllocator.h:114
const T * const_pointer
const pointer type
Definition: AlignedAllocator.h:37
size_t max_size() const noexcept
Returns maximum possible value of n, with which we can call allocate(n)
Definition: AlignedAllocator.h:78
void destroy(U *p)
Destroy object pointed to by p, but does not deallocate the memory.
Definition: AlignedAllocator.h:123
void deallocate(T *ptr, std::size_t)
Deallocate memory pointed to by ptr.
Definition: AlignedAllocator.h:105
AlignedAllocator(const AlignedAllocator< U, Alignment > &)
Copy constructor.
Definition: AlignedAllocator.h:66
AlignedAllocator()=default
Default empty constructor.
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
bool operator!=(const Configuration &lhs, const Configuration &rhs)
Not-Equals operator for Configuration objects.
Definition: Configuration.cpp:112
bool operator==(const Configuration &lhs, const Configuration &rhs)
Equals operator for Configuration objects.
Definition: Configuration.cpp:108
constexpr unsigned int DEFAULT_CACHE_LINE_SIZE
Default size for a cache line.
Definition: AlignedAllocator.h:21
Equivalent allocator for other types Class whose member other is an alias of allocator for type U.
Definition: AlignedAllocator.h:52