Go to the documentation of this file.
3 #ifndef DUNE_ALIGNED_ALLOCATOR_HH
4 #define DUNE_ALIGNED_ALLOCATOR_HH
19 template<
class T,
int Alignment = -1>
34 static constexpr
int fixAlignment(
int align)
36 return ((Alignment==-1) ? std::alignment_of<T>::value : Alignment) > align
37 ? fixAlignment(align << 1) : align;
46 static constexpr
int fixAlignment(
int align)
48 return (Alignment==-1) ? std::alignment_of<T>::value : Alignment;
60 static constexpr
int alignment = fixAlignment(
sizeof(
void*));
68 throw std::bad_alloc();
77 if (posix_memalign(&ret,
alignment, n *
sizeof(T)) != 0)
78 throw std::bad_alloc();
80 return static_cast<pointer>(ret);
87 throw std::bad_alloc();
96 #endif // DUNE_ALIGNED_ALLOCATOR_HH
typename MallocAllocator< T >::pointer pointer
Definition: alignedallocator.hh:54
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
Dune namespace.
Definition: alignedallocator.hh:9
T * pointer
Definition: mallocallocator.hh:27
pointer allocate(size_type n, const void *hint=0)
allocate n objects of type T
Definition: alignedallocator.hh:63
Allocators which guarantee alignment of the memory.
Definition: alignedallocator.hh:20
Definition: alignedallocator.hh:56
std::size_t size_type
Definition: mallocallocator.hh:25
Allocators that use malloc/free.
static constexpr int alignment
Definition: alignedallocator.hh:60
Allocators implementation which simply calls malloc/free.
Definition: mallocallocator.hh:23
typename MallocAllocator< T >::size_type size_type
Definition: alignedallocator.hh:55
AlignedAllocator< U, Alignment > other
Definition: alignedallocator.hh:57
size_type max_size() const noexcept
max size for allocate
Definition: mallocallocator.hh:75