Graphite  Version 3
An experimental 3D geometry processing program
GEO::Memory Namespace Reference

Utilities for memory management. More...

Classes

struct  PointAlignment
 Defines the memory alignment of points in a vector. More...
 
struct  PointAlignment< 2 >
 PointAlignment specialization for points of dimension 2. More...
 
struct  PointAlignment< 3 >
 PointAlignment specialization for points of dimension 3. More...
 
struct  PointAlignment< 4 >
 PointAlignment specialization for points of dimension 4. More...
 
struct  PointAlignment< 6 >
 PointAlignment specialization for points of dimension 6. More...
 
struct  PointAlignment< 8 >
 PointAlignment specialization for points of dimension 8. More...
 
class  aligned_allocator
 An allocator that performs aligned memory allocations. More...
 

Typedefs

typedef unsigned char byte
 Unsigned byte type.
 
typedef unsigned char word8
 Unsigned 8 bits integer.
 
typedef unsigned short word16
 Unsigned 16 bits integer.
 
typedef unsigned int word32
 Unsigned 32 bits integer.
 
typedef bytepointer
 Pointer to unsigned byte(s)
 
typedef void(* function_pointer) ()
 Generic function pointer.
 

Functions

void clear (void *addr, size_t size)
 Clears a memory block. More...
 
void copy (void *to, const void *from, size_t size)
 Copies a memory block. More...
 
pointer function_pointer_to_generic_pointer (function_pointer fptr)
 Converts a function pointer to a generic pointer. More...
 
function_pointer generic_pointer_to_function_pointer (pointer ptr)
 Converts a generic pointer to a function pointer. More...
 
function_pointer generic_pointer_to_function_pointer (void *ptr)
 Converts a generic pointer to a function pointer. More...
 
void * aligned_malloc (size_t size, size_t alignment=GEO_MEMORY_ALIGNMENT)
 Allocates aligned memory. More...
 
void aligned_free (void *p)
 Deallocates aligned memory. More...
 
bool is_aligned (void *p, size_t alignment=GEO_MEMORY_ALIGNMENT)
 Checks whether a pointer is aligned. More...
 
void * align (void *p)
 Returns the smallest aligned memory address from p.
 
template<typename T1 , int A1, typename T2 , int A2>
bool operator== (const aligned_allocator< T1, A1 > &, const aligned_allocator< T2, A2 > &)
 Tests whether two aligned_allocators are equal. More...
 
template<typename T1 , int A1, typename T2 , int A2>
bool operator!= (const aligned_allocator< T1, A1 > &, const aligned_allocator< T2, A2 > &)
 Tests whether two aligned_allocators are different. More...
 

Detailed Description

Utilities for memory management.

Function Documentation

◆ aligned_free()

void GEO::Memory::aligned_free ( void *  p)
inline

Deallocates aligned memory.

Deallocates the block of memory pointed to by p. Note p that must have been previously allocated by aligned_malloc()

See also
aligned_malloc()
Note
Memory alignment is not supported under Android.

Definition at line 309 of file memory.h.

◆ aligned_malloc()

void* GEO::Memory::aligned_malloc ( size_t  size,
size_t  alignment = GEO_MEMORY_ALIGNMENT 
)
inline

Allocates aligned memory.

The address of the allocated block will be a multiple of alignment. Aligned memory blocks are required by vector processing instructions (SSE, AVX...)

Parameters
[in]sizesize of the block to allocate
[in]alignmentmemory alignment (must be a power of 2)
Note
Memory alignment is not supported under Android.

Definition at line 281 of file memory.h.

◆ clear()

void GEO::Memory::clear ( void *  addr,
size_t  size 
)
inline

Clears a memory block.

Clears (set to zero) the first size bytes of array addr.

Parameters
[in]addran array of bytes
[in]sizethe number of bytes to clear

Definition at line 116 of file memory.h.

◆ copy()

void GEO::Memory::copy ( void *  to,
const void *  from,
size_t  size 
)
inline

Copies a memory block.

Copies the first size bytes of array from to array to. Note that this function has unpredictable results if the memory areas pointed to by to and from overlap.

Parameters
[in]tothe destination array of bytes
[in]fromthe array of bytes to copy
[in]sizethe number of bytes to copy

Definition at line 129 of file memory.h.

◆ function_pointer_to_generic_pointer()

pointer GEO::Memory::function_pointer_to_generic_pointer ( function_pointer  fptr)
inline

Converts a function pointer to a generic pointer.

In C++ it is not legal to convert between function pointers and generic pointers using casts. Such conversion may be required when retrieving symbols in dynamically linked libraries, or when interfacing with scripting languages.

Parameters
[in]fptrthe function pointer
Returns
a generic pointer with the same address as fptr

Definition at line 142 of file memory.h.

◆ generic_pointer_to_function_pointer() [1/2]

function_pointer GEO::Memory::generic_pointer_to_function_pointer ( pointer  ptr)
inline

Converts a generic pointer to a function pointer.

In C++ it is not legal to convert between function pointers and generic pointers using casts. Such conversion may be required when retrieving symbols in dynamically linked libraries, or when interfacing with scripting languages.

Parameters
[in]ptrthe generic pointer
Returns
a function pointer with the same address as ptr

Definition at line 161 of file memory.h.

◆ generic_pointer_to_function_pointer() [2/2]

function_pointer GEO::Memory::generic_pointer_to_function_pointer ( void *  ptr)
inline

Converts a generic pointer to a function pointer.

In C++ it is not legal to convert between function pointers and generic pointers using casts. Such conversion may be required when retrieving symbols in dynamically linked libraries, or when interfacing with scripting languages.

Parameters
[in]ptrthe generic pointer
Returns
a function pointer with the same address as ptr

Definition at line 180 of file memory.h.

◆ is_aligned()

bool GEO::Memory::is_aligned ( void *  p,
size_t  alignment = GEO_MEMORY_ALIGNMENT 
)
inline

Checks whether a pointer is aligned.

Parameters
[in]pthe pointer to check
[in]alignmentmemory alignment (must be a power of 2)
Return values
trueif is aligned on alignment bytes
falseotherwise

Definition at line 419 of file memory.h.

◆ operator!=()

template<typename T1 , int A1, typename T2 , int A2>
bool GEO::Memory::operator!= ( const aligned_allocator< T1, A1 > &  ,
const aligned_allocator< T2, A2 > &   
)
inline

Tests whether two aligned_allocators are different.

Returns
Always false.

Definition at line 617 of file memory.h.

◆ operator==()

template<typename T1 , int A1, typename T2 , int A2>
bool GEO::Memory::operator== ( const aligned_allocator< T1, A1 > &  ,
const aligned_allocator< T2, A2 > &   
)
inline

Tests whether two aligned_allocators are equal.

Returns
Always true.

Definition at line 606 of file memory.h.