37 #ifndef NEKTAR_LIB_UTILITIES_NEK_MEMORY_MANAGER_H
38 #define NEKTAR_LIB_UTILITIES_NEK_MEMORY_MANAGER_H
41 #include <type_traits>
43 #include <boost/core/ignore_unused.hpp>
82 template<
typename DataType>
101 #ifdef NEKTAR_MEMORY_POOL_ENABLED
105 #ifdef NEKTAR_USE_ALIGNED_MEM
106 boost::alignment::aligned_free(data);
115 #ifdef NEKTAR_MEMORY_POOL_ENABLED
123 template<
typename... Args>
124 static DataType*
Allocate(
const Args &...args)
126 DataType* result =
static_cast<DataType*
>(
133 new (result) DataType(args...);
152 template<typename... Args>
155 #ifdef NEKTAR_USE_ALIGNED_MEM
158 return new (ptr) DataType(args...);
160 return new DataType(args...);
170 template<
typename... Args>
176 template<
typename DeallocatorType,
typename... Args>
178 const DeallocatorType& d,
const Args &...args)
181 return std::shared_ptr<DataType>(
182 data, [=](DataType *ptr){
200 #ifdef NEKTAR_MEMORY_POOL_ENABLED
202 NumberOfElements *
sizeof(DataType)));
204 #ifdef NEKTAR_USE_ALIGNED_MEM
205 return static_cast<DataType*
>(boost::alignment::aligned_alloc(
207 NumberOfElements *
sizeof(DataType)));
209 return static_cast<DataType*
>(::operator
new(NumberOfElements *
sizeof(DataType)));
223 #ifdef NEKTAR_MEMORY_POOL_ENABLED
226 boost::ignore_unused(NumberOfElements);
227 #ifdef NEKTAR_USE_ALIGNED_MEM
228 boost::alignment::aligned_free(array);
230 ::operator
delete(array);
253 boost::ignore_unused(rhs);
262 boost::ignore_unused(hint);
273 new(
p) DataType(val);
283 return std::numeric_limits<size_type>::max()/
sizeof(DataType);
300 template<
typename DataType>
303 boost::ignore_unused(lhs,rhs);
307 template<
typename DataType>
310 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 std::shared_ptr< DataType > AllocateSharedPtrD(const DeallocatorType &d, const Args &...args)
void deallocate(pointer p, size_type n)
MemoryManager(const MemoryManager< T > &rhs)
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.
void construct(pointer p, const_reference val)
static void Deallocate(DataType *&data)
Deallocate a pointer allocated by MemoryManager::Allocate.
pointer allocate(size_type n, std::allocator< void >::const_pointer hint=0)
static DataType * Allocate(const Args &...args)
Allocates a single object from the memory pool.
const_pointer address(const_reference r) const
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.
The above copyright notice and this permission notice shall be included.
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 >::type simd