MathFu
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Friends Groups Pages
Allocators

SIMD-safe memory allocators. More...

Detailed Description

SIMD-safe memory allocators.

If you use MathFu with SIMD (SSE in particular), you need to have all your allocations be 16-byte aligned (which isn't the case with the default allocators on most platforms except OS X).

You can either use simd_allocator, which solves the problem for any STL containers, but not for manual dynamic allocations or the new/delete override MATHFU_DEFINE_GLOBAL_SIMD_AWARE_NEW_DELETE will solve it for all allocations, at the cost of MATHFU_ALIGNMENT bytes per allocation.

Classes

class  mathfu::simd_allocator< T >
 SIMD-safe memory allocator, for use with STL types like std::vector. More...
 

Macros

#define MATHFU_ALIGNMENT   16
 Alignment (in bytes) of memory allocated by AllocateAligned. More...
 
#define MATHFU_DEFINE_GLOBAL_SIMD_AWARE_NEW_DELETE
 Macro which overrides the default new and delete allocators. More...
 
#define MATHFU_DEFINE_CLASS_SIMD_AWARE_NEW_DELETE
 Macro which defines the new and delete for MathFu classes. More...
 

Functions

void * mathfu::AllocateAligned (size_t n)
 Allocate an aligned block of memory. More...
 
void mathfu::FreeAligned (void *p)
 Deallocate a block of memory allocated with AllocateAligned(). More...
 

Macro Definition Documentation

#define MATHFU_ALIGNMENT   16

Alignment (in bytes) of memory allocated by AllocateAligned.

See Also
mathfu::AllocateAligned()
mathfu::simd_allocator
#define MATHFU_DEFINE_CLASS_SIMD_AWARE_NEW_DELETE
Value:
static void *operator new(std::size_t n) { \
} \
static void *operator new[](std::size_t n) { \
} \
static void *operator new(std::size_t /*n*/, void *p) { return p; } \
static void *operator new[](std::size_t /*n*/, void *p) { return p; } \
static void operator delete(void *p) { mathfu::FreeAligned(p); } \
static void operator delete[](void *p) { mathfu::FreeAligned(p); } \
static void operator delete(void * /*p*/, void * /*place*/) {} \
static void operator delete[](void * /*p*/, void * /*place*/) {}
void * AllocateAligned(size_t n)
Allocate an aligned block of memory.
Definition: utilities.h:485
void FreeAligned(void *p)
Deallocate a block of memory allocated with AllocateAligned().
Definition: utilities.h:510

Macro which defines the new and delete for MathFu classes.

#define MATHFU_DEFINE_GLOBAL_SIMD_AWARE_NEW_DELETE
Value:
void *operator new(std::size_t n) { return mathfu::AllocateAligned(n); } \
void *operator new[](std::size_t n) { return mathfu::AllocateAligned(n); } \
void operator delete(void *p) noexcept { mathfu::FreeAligned(p); } \
void operator delete[](void *p) noexcept { mathfu::FreeAligned(p); }
void * AllocateAligned(size_t n)
Allocate an aligned block of memory.
Definition: utilities.h:485
void FreeAligned(void *p)
Deallocate a block of memory allocated with AllocateAligned().
Definition: utilities.h:510

Macro which overrides the default new and delete allocators.

To globally override new and delete, simply add the line:

MATHFU_DEFINE_GLOBAL_SIMD_AWARE_NEW_DELETE

to the end of your main .cpp file.

Function Documentation

void* mathfu::AllocateAligned ( size_t  n)
inline

Allocate an aligned block of memory.

This function allocates a block of memory aligned to MATHFU_ALIGNMENT bytes.

Parameters
nSize of memory to allocate.
Returns
Pointer to aligned block of allocated memory or NULL if allocation failed.
void mathfu::FreeAligned ( void *  p)
inline

Deallocate a block of memory allocated with AllocateAligned().

Parameters
pPointer to memory to deallocate.