waLBerla 7.3
Loading...
Searching...
No Matches
walberla::v8::memory::Allocator< T, Backend > Class Template Reference

Detailed Description

template<AllocatableType T, AllocatorBackend Backend>
class walberla::v8::memory::Allocator< T, Backend >

Aligned memory allocator with offset.

Template Parameters
TElement type to allocate.
BackendAllocator backend satisfying the AllocatorBackend concept.

#include <Allocators.hpp>

Classes

struct  rebind

Public Types

using value_type = T

Public Member Functions

 Allocator () noexcept=default
 Allocator (size_t offset, size_t alignment)
 Construct an allocator with a given offset and alignment.
T * allocate (size_t n)
 Allocate memory for n elements of type T.
void deallocate (T *ptr, size_t) noexcept
 Deallocate memory previously allocated by allocate.
size_t offset () const noexcept
size_t alignment () const noexcept
bool operator== (const Allocator &) const noexcept
bool operator!= (const Allocator &) const noexcept
template<typename U>
 Allocator (const Allocator< U, Backend > &other) noexcept

Private Attributes

size_t offset_ = 0
size_t align_ = alignof(T)
Backend backend_

Static Private Attributes

static std::map< void *, void * > outerToBase

Member Typedef Documentation

◆ value_type

template<AllocatableType T, AllocatorBackend Backend>
using walberla::v8::memory::Allocator< T, Backend >::value_type = T

Constructor & Destructor Documentation

◆ Allocator() [1/3]

template<AllocatableType T, AllocatorBackend Backend>
walberla::v8::memory::Allocator< T, Backend >::Allocator ( )
defaultnoexcept

◆ Allocator() [2/3]

template<AllocatableType T, AllocatorBackend Backend>
walberla::v8::memory::Allocator< T, Backend >::Allocator ( size_t offset,
size_t alignment )
inline

Construct an allocator with a given offset and alignment.

Parameters
offsetNumber of bytes into the data block which sepcifies the aligned region.
alignmentRequired byte alignment.
Exceptions
std::runtime_errorif alignment is less than alignof(T) or not a power of two.

◆ Allocator() [3/3]

template<AllocatableType T, AllocatorBackend Backend>
template<typename U>
walberla::v8::memory::Allocator< T, Backend >::Allocator ( const Allocator< U, Backend > & other)
inlinenoexcept

Member Function Documentation

◆ alignment()

template<AllocatableType T, AllocatorBackend Backend>
size_t walberla::v8::memory::Allocator< T, Backend >::alignment ( ) const
inlinenoexcept

◆ allocate()

template<AllocatableType T, AllocatorBackend Backend>
T * walberla::v8::memory::Allocator< T, Backend >::allocate ( size_t n)
inlinenodiscard

Allocate memory for n elements of type T.

The returned (outer) pointer satisfies the offset and alignment requirement such that:

(reinterpret_cast<uintptr_t>(outer) + offset) % alignment == 0
size_t offset() const noexcept
Definition Allocators.hpp:152
size_t alignment() const noexcept
Definition Allocators.hpp:153

The original (base) pointer is stored internally and recovered during deallocation. Memory layout:

<-------------------------- (data) n*sizeof(T) -------------------------->
<------ unused ------><--------- offset --------->
[base]================[outer]=====================[inner (aligned)]=============================
Parameters
nNumber of elements to allocate.
Returns
Pointer to the outer memory region.
Exceptions
std::bad_array_new_lengthif the allocation size overflows.
std::bad_allocif the offset is larger than the data itself.

◆ deallocate()

template<AllocatableType T, AllocatorBackend Backend>
void walberla::v8::memory::Allocator< T, Backend >::deallocate ( T * ptr,
size_t  )
inlinenoexcept

Deallocate memory previously allocated by allocate.

Recovers the original base pointer from the internal map and frees it.

Parameters
ptrPointer previously returned by allocate.

◆ offset()

template<AllocatableType T, AllocatorBackend Backend>
size_t walberla::v8::memory::Allocator< T, Backend >::offset ( ) const
inlinenoexcept

◆ operator!=()

template<AllocatableType T, AllocatorBackend Backend>
bool walberla::v8::memory::Allocator< T, Backend >::operator!= ( const Allocator< T, Backend > & ) const
inlinenoexcept

◆ operator==()

template<AllocatableType T, AllocatorBackend Backend>
bool walberla::v8::memory::Allocator< T, Backend >::operator== ( const Allocator< T, Backend > & ) const
inlinenoexcept

Member Data Documentation

◆ align_

template<AllocatableType T, AllocatorBackend Backend>
size_t walberla::v8::memory::Allocator< T, Backend >::align_ = alignof(T)
private

◆ backend_

template<AllocatableType T, AllocatorBackend Backend>
Backend walberla::v8::memory::Allocator< T, Backend >::backend_
private

◆ offset_

template<AllocatableType T, AllocatorBackend Backend>
size_t walberla::v8::memory::Allocator< T, Backend >::offset_ = 0
private

◆ outerToBase

template<AllocatableType T, AllocatorBackend Backend>
std::map<void*, void*> walberla::v8::memory::Allocator< T, Backend >::outerToBase
inlinestaticprivate

The documentation for this class was generated from the following file:
  • /builds/administration/walberla-website/walberla/include/walberla/v8/memory/Allocators.hpp