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);
85 pointer ret =
static_cast<pointer>(aligned_alloc(alignment, n *
sizeof(T)));
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
Allocators implementation which simply calls malloc/free.
Definition: mallocallocator.hh:23
Allocators that use malloc/free.
Allocators which guarantee alignment of the memory.
Definition: alignedallocator.hh:20
pointer allocate(size_type n, const void *hint=0)
allocate n objects of type T
Definition: alignedallocator.hh:63
Dune namespace.
Definition: alignedallocator.hh:9
typename MallocAllocator< T >::size_type size_type
Definition: alignedallocator.hh:55
size_type max_size() const noexcept
max size for allocate
Definition: mallocallocator.hh:75
Definition: alignedallocator.hh:56
static constexpr int alignment
Definition: alignedallocator.hh:60
std::size_t size_type
Definition: mallocallocator.hh:25
AlignedAllocator< U, Alignment > other
Definition: alignedallocator.hh:57
T * pointer
Definition: mallocallocator.hh:27