ls1-MarDyn
ls1-MarDyn molecular dynamics code
Classes | Public Types | Public Member Functions | List of all members
AlignedAllocator< T, Alignment > Struct Template Reference

A custom allocator to get aligned memory. More...

#include <AlignedAllocator.h>

Classes

struct  rebind
 

Public Types

typedef T value_type
 
typedef T * pointer
 
typedef const T * const_pointer
 
typedef T & reference
 
typedef const T & const_reference
 
typedef size_t size_type
 

Public Member Functions

 AlignedAllocator ()=default
 Default constructor.
 
template<class U >
 AlignedAllocator (const AlignedAllocator< U, Alignment > &)
 Copy constructor.
 
size_t max_size () const noexcept
 Returns maximum possible value of n, with which we can call allocate(n)
 
T * allocate (std::size_t n)
 Allocate aligned memory for n objects of type T. More...
 
void deallocate (T *ptr, std::size_t)
 Deallocate memory pointed to by ptr.
 
template<class U , class ... Args>
void construct (U *p, Args &&... args)
 Construct object of type U at already allocated memory, pointed to by p.
 
template<class U >
void destroy (U *p)
 Destroy object pointed to by p, but does not deallocate the memory.
 

Detailed Description

template<typename T, size_t Alignment = CACHE_LINE_SIZE>
struct AlignedAllocator< T, Alignment >

A custom allocator to get aligned memory.

This allocator is intended to be used by std::vector

Template Parameters
TThe type of the elements this class should allocate memory for
alignmentThe alignment restriction. Must be a power of 2, should not be 8.
Author
Micha Mueller

Member Function Documentation

◆ allocate()

template<typename T , size_t Alignment = CACHE_LINE_SIZE>
T* AlignedAllocator< T, Alignment >::allocate ( std::size_t  n)
inline

Allocate aligned memory for n objects of type T.

Returns
Pointer to the allocated memory

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