dune-common 2.12-git
Loading...
Searching...
No Matches
Dune::AlignedAllocator< T, MinAlignment > Class Template Reference

Allocators which guarantee a minimum alignment of the memory. More...

#include <dune/common/alignedallocator.hh>

Classes

struct  rebind
 Rebind allocator to type U. More...
 

Public Types

using value_type = T
 Type of the object to allocate.
 

Public Member Functions

 AlignedAllocator () noexcept=default
 Default constructor.
 
template<class U >
 AlignedAllocator (const AlignedAllocator< U, MinAlignment > &) noexcept
 Construct an aligned allocator from another aligned allocator of different type.
 
T * allocate (std::size_t n)
 Allocate n objects of type T.
 
void deallocate (T *p, std::size_t n)
 Deallocate memory previously allocated with allocate()
 

Static Public Attributes

static constexpr std::size_t alignment = std::max(MinAlignment, std::alignment_of<T>::value)
 Alignment of the allocated memory.
 

Detailed Description

template<class T, std::size_t MinAlignment = 1>
class Dune::AlignedAllocator< T, MinAlignment >

Allocators which guarantee a minimum alignment of the memory.

This allocator provides a simple interface to allocate memory with a minimum alignment. The actual alignment of the allocated memory is the maximum of the minimum alignment and the alignment of the type T. This ensures that the allocated memory is always aligned to the requirements of the type T, while also allowing for bigger alignments when needed. Note that the minimum alignment is also guaranteed in rebinding, i.e. when allocating memory for a different type U.

Template Parameters
TType of the object one wants to allocate
MinAlignmentMinimum alignment of the allocated memory.

Member Typedef Documentation

◆ value_type

template<class T , std::size_t MinAlignment = 1>
using Dune::AlignedAllocator< T, MinAlignment >::value_type = T

Type of the object to allocate.

Constructor & Destructor Documentation

◆ AlignedAllocator() [1/2]

template<class T , std::size_t MinAlignment = 1>
Dune::AlignedAllocator< T, MinAlignment >::AlignedAllocator ( )
defaultnoexcept

Default constructor.

◆ AlignedAllocator() [2/2]

template<class T , std::size_t MinAlignment = 1>
template<class U >
Dune::AlignedAllocator< T, MinAlignment >::AlignedAllocator ( const AlignedAllocator< U, MinAlignment > &  )
inlinenoexcept

Construct an aligned allocator from another aligned allocator of different type.

Member Function Documentation

◆ allocate()

template<class T , std::size_t MinAlignment = 1>
T * Dune::AlignedAllocator< T, MinAlignment >::allocate ( std::size_t  n)
inline

Allocate n objects of type T.

Parameters
nNumber of objects to allocate
Returns
Pointer to the allocated memory

◆ deallocate()

template<class T , std::size_t MinAlignment = 1>
void Dune::AlignedAllocator< T, MinAlignment >::deallocate ( T *  p,
std::size_t  n 
)
inline

Deallocate memory previously allocated with allocate()

Parameters
pPointer to the memory to deallocate
nNumber of objects to deallocate

Member Data Documentation

◆ alignment

template<class T , std::size_t MinAlignment = 1>
constexpr std::size_t Dune::AlignedAllocator< T, MinAlignment >::alignment = std::max(MinAlignment, std::alignment_of<T>::value)
staticconstexpr

Alignment of the allocated memory.


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