Geogram Version 1.9.8
A programming library of geometric algorithms
Loading...
Searching...
No Matches
GEO::Memory Namespace Reference

Utilities for memory management. More...

Classes

class  aligned_allocator
 An allocator that performs aligned memory allocations. More...
 
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...
 

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 const byteconst_pointer
 Const pointer to unsigned byte(s)
 
typedef void(* function_pointer) ()
 Generic function pointer.
 

Functions

void clear (void *addr, size_t size)
 Clears a memory block.
 
void copy (void *to, const void *from, size_t size)
 Copies a memory block.
 
template<class FPTR = function_pointer>
pointer function_pointer_to_generic_pointer (FPTR fptr)
 Converts a function pointer to a generic pointer.
 
template<class FPTR = function_pointer>
FPTR generic_pointer_to_function_pointer (pointer ptr)
 Converts a generic pointer to a function pointer.
 
template<class FPTR = function_pointer>
FPTR generic_pointer_to_function_pointer (void *ptr)
 Converts a generic pointer to a function pointer.
 
template<class T >
T & pointer_as_reference (void *ptr)
 Converts a pointer to a reference.
 
template<class T >
const T & pointer_as_reference (const void *ptr)
 Converts a const pointer to a reference.
 
void * aligned_malloc (size_t size, size_t alignment=GEO_MEMORY_ALIGNMENT)
 Allocates aligned memory.
 
void aligned_free (void *p)
 Deallocates aligned memory.
 
bool is_aligned (void *p, size_t alignment=GEO_MEMORY_ALIGNMENT)
 Checks whether a pointer is aligned.
 
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.
 
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.
 

Detailed Description

Utilities for memory management.

Typedef Documentation

◆ byte

typedef unsigned char GEO::Memory::byte

Unsigned byte type.

Definition at line 92 of file memory.h.

◆ const_pointer

Const pointer to unsigned byte(s)

Definition at line 107 of file memory.h.

◆ function_pointer

typedef void(* GEO::Memory::function_pointer) ()

Generic function pointer.

Definition at line 110 of file memory.h.

◆ pointer

Pointer to unsigned byte(s)

Definition at line 104 of file memory.h.

◆ word16

typedef unsigned short GEO::Memory::word16

Unsigned 16 bits integer.

Definition at line 98 of file memory.h.

◆ word32

typedef unsigned int GEO::Memory::word32

Unsigned 32 bits integer.

Definition at line 101 of file memory.h.

◆ word8

typedef unsigned char GEO::Memory::word8

Unsigned 8 bits integer.

Definition at line 95 of file memory.h.

Function Documentation

◆ align()

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

Returns the smallest aligned memory address from p.

Definition at line 472 of file memory.h.

◆ 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 352 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 324 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 119 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 132 of file memory.h.

◆ function_pointer_to_generic_pointer()

template<class FPTR = function_pointer>
pointer GEO::Memory::function_pointer_to_generic_pointer ( FPTR  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.

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

Definition at line 147 of file memory.h.

◆ generic_pointer_to_function_pointer() [1/2]

template<class FPTR = function_pointer>
FPTR 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.

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

Definition at line 166 of file memory.h.

◆ generic_pointer_to_function_pointer() [2/2]

template<class FPTR = function_pointer>
FPTR 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.

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

Definition at line 185 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 463 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 692 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 681 of file memory.h.

◆ pointer_as_reference() [1/2]

template<class T >
const T & GEO::Memory::pointer_as_reference ( const void *  ptr)
inline

Converts a const pointer to a reference.

Template Parameters
Tthe type for the reference
Parameters
[in]ptrthe pointer
Returns
a const reference of type const T&

Definition at line 217 of file memory.h.

◆ pointer_as_reference() [2/2]

template<class T >
T & GEO::Memory::pointer_as_reference ( void *  ptr)
inline

Converts a pointer to a reference.

Template Parameters
Tthe type for the reference
Parameters
[in]ptrthe pointer
Returns
a reference of type T&

Definition at line 200 of file memory.h.