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;
54 using pointer =
typename MallocAllocator<T>::pointer;
55 using size_type =
typename MallocAllocator<T>::size_type;
56 template <
class U>
struct rebind {
60 static constexpr int alignment = fixAlignment(
sizeof(
void*));
63 pointer
allocate(size_type n,
const void* hint = 0)
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();
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
Allocators implementation which simply calls malloc/free.
Definition: mallocallocator.hh:23
size_type max_size() const noexcept
max size for allocate
Definition: mallocallocator.hh:75
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
Allocators that use malloc/free.
Dune namespace.
Definition: alignedallocator.hh:10