GemaCoreLib
The GeMA Core library
Macros | Functions
gmMemory.h File Reference

Implementation of the custom allocator used by Armadillo when memory is needed for matrices and vectors. More...

#include "gmCoreConfig.h"
#include <assert.h>
#include "gmOmp.h"
Include dependency graph for gmMemory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define GM_CACHE_LINE_SIZE   64
 Cache line size. TODO: Get this from a configuration parameter.
 
#define GM_CACHE_ALIGNED   __attribute__((aligned(GM_CACHE_LINE_SIZE)))
 
#define GmAlignedFree(ptr)   ::free(ptr)
 

Functions

void * GmAlignedMalloc (size_t size, size_t align)
 
void * GmAlignedMallocThrow (size_t size, size_t align)
 A version of GmAlignedMalloc that throws a bad_alloc exception on failure.
 
bool GmMemoryIsAligned (void *ptr, int align)
 Checks if a pointer is aligned to the given align (which must be a power of two)
 
bool GmIsCacheAligned (void *ptr)
 Checks if a pointer is cache aligned or not.
 
template<class T >
void GmConstructObjectsInMemory (T *ptr, int n=1)
 Calls the default T constructor for creating 'n' consecutive objects in the memory area pointed by ptr. More...
 
template<class T >
void GmDestroyObjectsInMemory (T *ptr, int n=1)
 Calls T destructor for 'n' consecutive objects in the memory area pointed by ptr. More...
 
template<class T >
void GmConstructAlignedObjectsInMemory (T *ptr, int align, int n)
 Calls the default T constructor for creating 'n' aligned objects in the memory area pointed by ptr. More...
 
template<class T >
void GmDestroyAlignedObjectsInMemory (T *ptr, int align, int n)
 Calls T destructor for 'n' aligned objects in the memory area pointed by ptr. More...
 
void * GmPmemcpy (void *dst, const void *src, size_t n, int nt=0, size_t min=10 *1024 *1024)
 Parallel (thread enabled) version of memcpy using OpenMP. More...
 

Detailed Description

Implementation of the custom allocator used by Armadillo when memory is needed for matrices and vectors.

Declaration of the custom allocator used by Armadillo when memory is needed for matrices and vectors.

Author
Carlos Augusto Teixeira Mendes
Date
march, 2019

Function Documentation

◆ GmConstructAlignedObjectsInMemory()

template<class T >
void GmConstructAlignedObjectsInMemory ( T *  ptr,
int  align,
int  n 
)

Calls the default T constructor for creating 'n' aligned objects in the memory area pointed by ptr.

The constructor is called only if the type T is a complex type as seen by QTypeInfo<T>. For plain old types, the memory is NOT initialized.

◆ GmConstructObjectsInMemory()

template<class T >
void GmConstructObjectsInMemory ( T *  ptr,
int  n = 1 
)

Calls the default T constructor for creating 'n' consecutive objects in the memory area pointed by ptr.

The constructor is called only if the type T is a complex type as seen by QTypeInfo<T>. For plain old types, the memory is NOT initialized.

◆ GmDestroyAlignedObjectsInMemory()

template<class T >
void GmDestroyAlignedObjectsInMemory ( T *  ptr,
int  align,
int  n 
)

Calls T destructor for 'n' aligned objects in the memory area pointed by ptr.

The constructor is called only if the type T is a complex type as seen by QTypeInfo<T>.

◆ GmDestroyObjectsInMemory()

template<class T >
void GmDestroyObjectsInMemory ( T *  ptr,
int  n = 1 
)

Calls T destructor for 'n' consecutive objects in the memory area pointed by ptr.

The constructor is called only if the type T is a complex type as seen by QTypeInfo<T>.

◆ GmPmemcpy()

void* GmPmemcpy ( void *  dst,
const void *  src,
size_t  n,
int  nt = 0,
size_t  min = 10 * 1024 * 1024 
)
inline

Parallel (thread enabled) version of memcpy using OpenMP.

The extra parameter nt controls the number of requested threads. A value of 0 (or -1 for compatibility with GmThreadManager) means that omp_get_max_threads() will be used.

The extra parameter min gives the minimum value of n for which the parallel version will be enabled. This value MUST be greater than the maximum number of threads.