SUNphi
1.0
|
#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. | |
Memory manager.
Definition at line 23 of file Memory.hpp.
|
inline |
|
inlineprivate |
Get aligned memory
Call the system routine which allocate memory
Result
Returned condition
size | Amount of memory to allocate |
alignment | Required alignment |
Definition at line 52 of file Memory.hpp.
|
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.
|
inlineprivate |
Move the allocated memory to cache.
Size of pointed memory
ptr | Pointer to the memory to move to cache |
Definition at line 186 of file Memory.hpp.
|
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.
|
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
ptr | Pointer to the memory to move to cache |
Definition at line 92 of file Memory.hpp.
|
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.
|
inlineprivate |
Adds a memory to cache.
Definition at line 117 of file Memory.hpp.
|
inline |
Decleare unused the memory.
ptr | Pointer getting freed |
Definition at line 246 of file Memory.hpp.
|
inline |
Release all used memory.
Iterator on elements to release
Pointer to memory to release
Definition at line 258 of file Memory.hpp.