37#ifndef NEKTAR_LIB_UTILITIES_NEK_MEMORY_MANAGER_H
38#define NEKTAR_LIB_UTILITIES_NEK_MEMORY_MANAGER_H
98#ifdef NEKTAR_MEMORY_POOL_ENABLED
102#ifdef NEKTAR_USE_ALIGNED_MEM
103 boost::alignment::aligned_free(data);
112#ifdef NEKTAR_MEMORY_POOL_ENABLED
120 template <
typename... Args>
static DataType *
Allocate(
const Args &...args)
129 new (result) DataType(args...);
148 template <typename... Args> static DataType *Allocate(const Args &...args)
150#ifdef NEKTAR_USE_ALIGNED_MEM
151 void *ptr = boost::alignment::aligned_alloc(
153 return new (ptr) DataType(args...);
155 return new DataType(args...);
165 template <
typename... Args>
171 template <
typename DeallocatorType,
typename... Args>
173 const DeallocatorType &
d,
const Args &...args)
176 return std::shared_ptr<DataType>(data, [=](DataType *ptr) {
194#ifdef NEKTAR_MEMORY_POOL_ENABLED
195 return static_cast<DataType *
>(
198#ifdef NEKTAR_USE_ALIGNED_MEM
199 return static_cast<DataType *
>(boost::alignment::aligned_alloc(
201 NumberOfElements *
sizeof(DataType)));
203 return static_cast<DataType *
>(
204 ::operator
new(NumberOfElements *
sizeof(DataType)));
217 [[maybe_unused]]
size_t NumberOfElements)
219#ifdef NEKTAR_MEMORY_POOL_ENABLED
222#ifdef NEKTAR_USE_ALIGNED_MEM
223 boost::alignment::aligned_free(array);
225 ::operator
delete(array);
273 new (
p) DataType(val);
283 return std::numeric_limits<size_type>::max() /
sizeof(DataType);
298template <
typename DataType>
305template <
typename DataType>
309 return !(lhs == rhs);
void Deallocate(void *p, size_t bytes)
Deallocate memory claimed by an earlier call to allocate.
void * Allocate(size_t bytes)
Allocate a block of memory of size ByteSize.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static DataType * RawAllocate(size_t NumberOfElements)
Allocates a chunk of raw, uninitialized memory, capable of holding NumberOfElements objects.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
void deallocate(pointer p, size_type n)
pointer address(reference r) const
ptrdiff_t difference_type
const DataType * const_pointer
const DataType & const_reference
static void RawDeallocate(DataType *array, size_t NumberOfElements)
Deallocates memory allocated from RawAllocate.
MemoryManager(const MemoryManager< T > &rhs)=delete
void construct(pointer p, const_reference val)
static std::shared_ptr< DataType > AllocateSharedPtrD(const DeallocatorType &d, const Args &...args)
static void Deallocate(DataType *&data)
Deallocate a pointer allocated by MemoryManager::Allocate.
const_pointer address(const_reference r) const
pointer allocate(size_type n)
static DataType * Allocate(const Args &...args)
Allocates a single object from the memory pool.
std::vector< double > d(NPUPPER *NPUPPER)
bool operator==(const Array< OneD, T1 > &lhs, const Array< OneD, T2 > &rhs)
MemPool & GetMemoryPool()
bool operator!=(const Array< OneD, T1 > &lhs, const Array< OneD, T2 > &rhs)
typename abi< ScalarType, width >::type simd