5#ifndef DUNE_ALIGNED_ALLOCATOR_HH
6#define DUNE_ALIGNED_ALLOCATOR_HH
22 template<
class T,
int Alignment = -1>
37 static constexpr int fixAlignment(
int align)
39 return ((Alignment==-1) ? std::alignment_of<T>::value : Alignment) > align
40 ? fixAlignment(align << 1) : align;
49 static constexpr int fixAlignment(
int align)
51 return (Alignment==-1) ? std::alignment_of<T>::value : Alignment;
57 using pointer =
typename MallocAllocator<T>::pointer;
58 using size_type =
typename MallocAllocator<T>::size_type;
59 template <
class U>
struct rebind {
63 static constexpr int alignment = fixAlignment(
sizeof(
void*));
66 pointer
allocate(size_type n, [[maybe_unused]]
const void* hint = 0)
69 throw std::bad_alloc();
74 size_type size = n *
sizeof(T) >= alignment ? n *
sizeof(T) : alignment;
76 size_type size = n *
sizeof(T);
82 pointer ret =
static_cast<pointer
>(std::aligned_alloc(alignment, size));
84 throw std::bad_alloc();
Allocators which guarantee alignment of the memory.
Definition: alignedallocator.hh:23
pointer allocate(size_type n, const void *hint=0)
allocate n objects of type T
Definition: alignedallocator.hh:66
Allocators implementation which simply calls malloc/free.
Definition: mallocallocator.hh:24
size_type max_size() const noexcept
max size for allocate
Definition: mallocallocator.hh:74
Allocators that use malloc/free.
Dune namespace.
Definition: alignedallocator.hh:13