Gromacs  2016.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Classes | Public Types | Public Member Functions
gmx::AlignedAllocator< T > Class Template Reference

#include <gromacs/utility/alignedallocator.h>

Description

template<class T>
class gmx::AlignedAllocator< T >

Aligned memory allocator.

Template Parameters
TType of objects to allocate

This class can be used for the optional allocator template parameter in standard library containers, which is necessary e.g. to use SIMD aligned load and store operations in those containers. The memory will always be aligned to 128 bytes, which is our estimate of the longest cache lines on architectures currently in use. It will also be padded by the same amount at the end of the area, to help avoid false cache sharing.

Exceptions
std::bad_allocInstead of a GROMACS exception object we throw the standard one on allocation failures to make it as compatible as possible with the errors expected by code using the standard library containers.

Classes

struct  rebind
 Standard-required typedef to use allocator with different class. More...
 

Public Types

typedef T value_type
 Type of allocated elements.
 
typedef T & reference
 Reference to allocated elements.
 
typedef const T & const_reference
 Constant reference to allocated elements.
 
typedef T * pointer
 Pointer to allocated elements.
 
typedef const T * const_pointer
 Constant pointer to allocated elements.
 
typedef std::size_t size_type
 Integer type to use for size of objects.
 
typedef std::ptrdiff_t difference_type
 Type to hold differences between pointers.
 

Public Member Functions

template<class U >
 AlignedAllocator (const AlignedAllocator< U > &)
 Templated copy constructor. More...
 
 AlignedAllocator ()
 Constructor. More...
 
pointer address (reference r) const
 Return address of an object. More...
 
const_pointer address (const_reference r) const
 Return address of a const object. More...
 
pointer allocate (std::size_t n, typename std::allocator< void >::const_pointer hint=0)
 Do the actual memory allocation. More...
 
void deallocate (pointer p, std::size_t n)
 Release memory. More...
 
template<class... Args>
void construct (pointer p, Args &&...args)
 Construct an object without allocating memory. More...
 
void destroy (pointer p)
 Call the destructor of object without releasing memory. More...
 
std::size_t max_size () const
 Return largest number of objects that can be allocated. More...
 
template<class T2 >
bool operator== (const AlignedAllocator< T2 > &rhs) const
 Return true if two allocators are identical. More...
 
bool operator!= (const AlignedAllocator &rhs) const
 Return true if two allocators are different. More...
 

Constructor & Destructor Documentation

template<class T >
template<class U >
gmx::AlignedAllocator< T >::AlignedAllocator ( const AlignedAllocator< U > &  )
inlineexplicit

Templated copy constructor.

This template constructor cannot be auto-generated, and is normally unused, except e.g. MSVC2015 standard library uses it in debug mode, presumably to implement some checks.

template<class T >
gmx::AlignedAllocator< T >::AlignedAllocator ( )
inline

Constructor.

No constructor can be auto-generated in the presence of any user-defined constructor, but we want the default constructor.

Member Function Documentation

template<class T >
pointer gmx::AlignedAllocator< T >::address ( reference  r) const
inline

Return address of an object.

Parameters
rReference to object of type T
Returns
Pointer to T memory
template<class T >
const_pointer gmx::AlignedAllocator< T >::address ( const_reference  r) const
inline

Return address of a const object.

Parameters
rConst reference to object of type T
Returns
Pointer to T memory
template<class T >
pointer gmx::AlignedAllocator< T >::allocate ( std::size_t  n,
typename std::allocator< void >::const_pointer  hint = 0 
)
inline

Do the actual memory allocation.

Parameters
nNumber of elements of type T to allocate. n can be 0 bytes, which will return a non-null properly aligned and padded pointer that should not be used.
hintOptional value returned from previous call to allocate. For now this is not used.
Returns
Pointer to allocated memory
Exceptions
std::bad_allocif the allocation fails.
template<class T >
template<class... Args>
void gmx::AlignedAllocator< T >::construct ( pointer  p,
Args &&...  args 
)
inline

Construct an object without allocating memory.

Template Parameters
ArgsVariable-length list of types for constructor args
Parameters
pAdress of memory where to construct object
argsVariable-length list of arguments to constructor
template<class T >
void gmx::AlignedAllocator< T >::deallocate ( pointer  p,
std::size_t  n 
)
inline

Release memory.

Parameters
pPointer to previously allocated memory returned from allocate()
nnumber of objects previously passed to allocate()
template<class T >
void gmx::AlignedAllocator< T >::destroy ( pointer  p)
inline

Call the destructor of object without releasing memory.

Parameters
pAddress of memory where to destroy object
template<class T >
std::size_t gmx::AlignedAllocator< T >::max_size ( ) const
inline

Return largest number of objects that can be allocated.

This will be set such that the number of objects T multiplied by the size of each object is the largest value that can be represented by size_type.

template<class T >
bool gmx::AlignedAllocator< T >::operator!= ( const AlignedAllocator< T > &  rhs) const
inline

Return true if two allocators are different.

Parameters
rhsOther allocator.

This is a member function of the left-hand-side allocator.

template<class T >
template<class T2 >
bool gmx::AlignedAllocator< T >::operator== ( const AlignedAllocator< T2 > &  rhs) const
inline

Return true if two allocators are identical.

Parameters
rhsOther allocator

This is a member function of the left-hand-side allocator.


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