SUNphi  1.0
SUNphi::Memory Class Reference

Memory manager. More...

#include <Memory.hpp>

Public Member Functions

void enableCache ()
 Enable cache usage.
 
void disableCache ()
 Disable cache usage.
 
template<class T = char>
T * provideAligned (const size_t nel, const size_t alignment)
 Allocate or get from cache after computing the proper size. More...
 
template<class T >
void release (T *ptr)
 Decleare unused the memory. More...
 
void releaseAllUsedMemory ()
 Release all used memory. More...
 
void clearCache ()
 Release all memory from cache. More...
 
template<typename T >
auto & printStatistics (T &&stream)
 Print to a stream.
 
 Memory ()
 Create the memory manager.
 
 ~Memory ()
 Destruct the memory manager. More...
 

Private Member Functions

void * allocateRawAligned (const size_t size, const size_t alignment)
 
void pushToUsed (void *ptr, const size_t size)
 Add to the list of used memory.
 
size_t popFromUsed (void *ptr)
 
void pushToCache (void *ptr, const size_t size)
 Adds a memory to cache. More...
 
void * popFromCache (const size_t &size, const size_t &alignment)
 Pop from the cache, returning to use. More...
 
void moveToCache (void *ptr)
 Move the allocated memory to cache. More...
 

Static Private Member Functions

static bool isAligned (const void *ptr, const size_t alignment)
 Check if a pointer is suitably aligned.
 

Private Attributes

std::map< void *, size_t > used
 List of dynamical allocated memory.
 
std::map< size_t, std::vector< void * > > cached
 List of cached allocated memory.
 
ValWithMax< size_t > usedSize
 Size of used memory.
 
ValWithMax< size_t > cachedSize
 Size of cached memory.
 
bool useCache {true}
 Use or not cache.
 
size_t nUnalignedAlloc {0}
 Number of unaligned allocation performed.
 
size_t nAlignedAlloc {0}
 Number of aligned allocation performed.
 
size_t nCachedReused {0}
 Number of cached memory reused.
 

Detailed Description

Memory manager.

Definition at line 23 of file Memory.hpp.

Constructor & Destructor Documentation

SUNphi::Memory::~Memory ( )
inline

Destruct the memory manager.

Indent current scope

Definition at line 330 of file Memory.hpp.

Member Function Documentation

void* SUNphi::Memory::allocateRawAligned ( const size_t  size,
const size_t  alignment 
)
inlineprivate

Get aligned memory

Call the system routine which allocate memory

Result

Returned condition

Parameters
sizeAmount of memory to allocate
alignmentRequired alignment

Definition at line 52 of file Memory.hpp.

void SUNphi::Memory::clearCache ( )
inline

Release all memory from cache.

Iterator to elements of the cached memory list

Number of elements to free

Size to be removed

Memory to free

Definition at line 280 of file Memory.hpp.

void SUNphi::Memory::moveToCache ( void *  ptr)
inlineprivate

Move the allocated memory to cache.

Size of pointed memory

Parameters
ptrPointer to the memory to move to cache

Definition at line 186 of file Memory.hpp.

void* SUNphi::Memory::popFromCache ( const size_t &  size,
const size_t &  alignment 
)
inlineprivate

Pop from the cache, returning to use.

List of memory with searched size

Vector of pointers

Get latest cached memory with appropriate alignment

Returned pointer, copied here before erasing

Definition at line 137 of file Memory.hpp.

size_t SUNphi::Memory::popFromUsed ( void *  ptr)
inlineprivate

Removes a pointer from the used list, without actually freeing associated memory

Returns the size of the memory pointed

Iterator to search result

Size of memory

Parameters
ptrPointer to the memory to move to cache

Definition at line 92 of file Memory.hpp.

template<class T = char>
T* SUNphi::Memory::provideAligned ( const size_t  nel,
const size_t  alignment 
)
inline

Allocate or get from cache after computing the proper size.

Total size to allocate

Allocated memory

Definition at line 217 of file Memory.hpp.

void SUNphi::Memory::pushToCache ( void *  ptr,
const size_t  size 
)
inlineprivate

Adds a memory to cache.

Parameters
ptrMemory to cache
sizeMemory size

Definition at line 117 of file Memory.hpp.

template<class T >
void SUNphi::Memory::release ( T *  ptr)
inline

Decleare unused the memory.

Parameters
ptrPointer getting freed

Definition at line 246 of file Memory.hpp.

void SUNphi::Memory::releaseAllUsedMemory ( )
inline

Release all used memory.

Iterator on elements to release

Pointer to memory to release

Definition at line 258 of file Memory.hpp.


The documentation for this class was generated from the following file: