Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GEO::Memory::aligned_allocator< T, ALIGN > Class Template Reference

An allocator that performs aligned memory allocations. More...

#include <geogram/basic/memory.h>

Classes

struct  rebind
 Defines the same allocator for other types. More...
 

Public Types

typedef T value_type
 Element type.
 
typedef T * pointer
 Pointer to element.
 
typedef T & reference
 Reference to element.
 
typedef const T * const_pointer
 Pointer to constant element.
 
typedef const T & const_reference
 Reference to constant element.
 
typedef ::std::size_t size_type
 Quantities of elements.
 
typedef ::std::ptrdiff_t difference_type
 Difference between two pointers.
 

Public Member Functions

pointer address (reference x)
 Gets the address of an object. More...
 
const_pointer address (const_reference x)
 Gets the address of a object. More...
 
pointer allocate (size_type nb_elt, const void *hint=nullptr)
 Allocates a block of storage. More...
 
void deallocate (pointer p, size_type nb_elt)
 Releases a block of storage. More...
 
size_type max_size () const
 Gets the maximum size possible to allocate. More...
 
void construct (pointer p, const_reference val)
 Constructs an object. More...
 
void destroy (pointer p)
 Destroys an object. More...
 
template<class T2 , int A2>
 operator aligned_allocator< T2, A2 > ()
 Conversion operator to different aligned_allocator. More...
 

Detailed Description

template<class T, int ALIGN = GEO_MEMORY_ALIGNMENT>
class GEO::Memory::aligned_allocator< T, ALIGN >

An allocator that performs aligned memory allocations.

The allocator can be used as a template argument for STL containers. It is required for efficient vectorization of the code using vector processing units (SSE,AVX or AVX-512).

Definition at line 456 of file memory.h.

Member Function Documentation

◆ address() [1/2]

template<class T , int ALIGN = GEO_MEMORY_ALIGNMENT>
const_pointer GEO::Memory::aligned_allocator< T, ALIGN >::address ( const_reference  x)
inline

Gets the address of a object.

Parameters
[in]xa const reference to an object of type T
Returns
a const_pointer to x

Definition at line 503 of file memory.h.

◆ address() [2/2]

template<class T , int ALIGN = GEO_MEMORY_ALIGNMENT>
pointer GEO::Memory::aligned_allocator< T, ALIGN >::address ( reference  x)
inline

Gets the address of an object.

Parameters
[in]xa reference to an object of type T
Returns
a pointer to x

Definition at line 494 of file memory.h.

◆ allocate()

template<class T , int ALIGN = GEO_MEMORY_ALIGNMENT>
pointer GEO::Memory::aligned_allocator< T, ALIGN >::allocate ( size_type  nb_elt,
const void *  hint = nullptr 
)
inline

Allocates a block of storage.

Attempts to allocate a block of storage with a size large enough to contain n elements of member type value_type (an alias of the allocator's template parameter), and returns a pointer to the first element. The storage is aligned on ALIGN bytes, but they are not constructed.

Parameters
[in]nb_eltnumber of elements to allocate
[in]hintEither 0 or a valer 0 or a value previously obtained by another call to allocate and not yet freed with deallocate. When it is not 0, this value may be used as a hint to improve performance by allocating the new block near the one specified. The address of an adjacent element is often a good choice.
Returns
A pointer to the initial element in the block of storage

Definition at line 524 of file memory.h.

◆ construct()

template<class T , int ALIGN = GEO_MEMORY_ALIGNMENT>
void GEO::Memory::aligned_allocator< T, ALIGN >::construct ( pointer  p,
const_reference  val 
)
inline

Constructs an object.

Constructs an element object on the location pointed by p. Notice that this does not allocate space for the element. It should already be available at p (see member allocate() to allocate space).

Parameters
[in]ppointer to a location with enough storage space to contain an element of type value_type.
[in]valvalue to initialize the constructed element to.
See also
allocate()

Definition at line 573 of file memory.h.

◆ deallocate()

template<class T , int ALIGN = GEO_MEMORY_ALIGNMENT>
void GEO::Memory::aligned_allocator< T, ALIGN >::deallocate ( pointer  p,
size_type  nb_elt 
)
inline

Releases a block of storage.

Releases a block of storage previously allocated with member allocate()) and not yet released. The elements in the array are not destroyed by a call to this member function.

Parameters
[in]pPointer to a block of storage previously allocated with aligned_allocator::allocate.
[in]nb_eltNumber of elements allocated on the call to aligned_allocator::allocate() for this block of storage.
See also
allocate()

Definition at line 545 of file memory.h.

◆ destroy()

template<class T , int ALIGN = GEO_MEMORY_ALIGNMENT>
void GEO::Memory::aligned_allocator< T, ALIGN >::destroy ( pointer  p)
inline

Destroys an object.

Destroys in-place the object pointed by p. Notice that this does not deallocate the storage for the element (see member deallocate() to release storage space).

Parameters
[in]ppointer to the object to be destroyed.
See also
deallocate()

Definition at line 585 of file memory.h.

◆ max_size()

template<class T , int ALIGN = GEO_MEMORY_ALIGNMENT>
size_type GEO::Memory::aligned_allocator< T, ALIGN >::max_size ( ) const
inline

Gets the maximum size possible to allocate.

Returns
the maximum number of elements, each of member type value_type that could potentially be allocated by a call to member allocate().

Definition at line 556 of file memory.h.

◆ operator aligned_allocator< T2, A2 >()

template<class T , int ALIGN = GEO_MEMORY_ALIGNMENT>
template<class T2 , int A2>
GEO::Memory::aligned_allocator< T, ALIGN >::operator aligned_allocator< T2, A2 > ( )
inline

Conversion operator to different aligned_allocator.

Required when compiling under MSVC version <= 2010

Definition at line 596 of file memory.h.


The documentation for this class was generated from the following file: