Gromacs
2016.6
|
#include <gromacs/utility/alignedallocator.h>
Aligned memory allocator.
T | Type 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.
std::bad_alloc | Instead 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... | |
|
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.
|
inline |
Constructor.
No constructor can be auto-generated in the presence of any user-defined constructor, but we want the default constructor.
|
inline |
Return address of an object.
r | Reference to object of type T |
|
inline |
Return address of a const object.
r | Const reference to object of type T |
|
inline |
Do the actual memory allocation.
n | Number 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. |
hint | Optional value returned from previous call to allocate. For now this is not used. |
std::bad_alloc | if the allocation fails. |
|
inline |
Construct an object without allocating memory.
Args | Variable-length list of types for constructor args |
p | Adress of memory where to construct object |
args | Variable-length list of arguments to constructor |
|
inline |
Release memory.
p | Pointer to previously allocated memory returned from allocate() |
n | number of objects previously passed to allocate() |
|
inline |
Call the destructor of object without releasing memory.
p | Address of memory where to destroy object |
|
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.
|
inline |
Return true if two allocators are different.
rhs | Other allocator. |
This is a member function of the left-hand-side allocator.
|
inline |
Return true if two allocators are identical.
rhs | Other allocator |
This is a member function of the left-hand-side allocator.