Block-Structured AMR Software Framework
AMReX_DataAllocator.H
Go to the documentation of this file.
1 #ifndef AMREX_DATA_ALLOCATOR_H_
2 #define AMREX_DATA_ALLOCATOR_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_Arena.H>
6 
7 namespace amrex {
8 
9 struct DataAllocator {
10  Arena* m_arena = nullptr;
11 
12  DataAllocator () noexcept = default;
13 
14  DataAllocator (Arena* ar) noexcept : m_arena(ar) {}
15 
16  [[nodiscard]] void* alloc (std::size_t sz) const noexcept {
17  return arena()->alloc(sz);
18  }
19 
20  void free (void* pt) const noexcept {
21  arena()->free(pt);
22  }
23 
24  [[nodiscard]] Arena* arena () const noexcept {
25  return (m_arena) ? m_arena : The_Arena();
26  }
27 };
28 
29 struct DataDeleter {
30  Arena* m_arena = nullptr;
31  DataDeleter () noexcept = default;
32  DataDeleter (Arena* ar) noexcept : m_arena(ar) {}
33  [[nodiscard]] Arena* arena () const noexcept { return (m_arena) ? m_arena : The_Arena(); }
34  void operator() (void* pt) const noexcept { arena()->free(pt); }
35 };
36 
37 }
38 
39 #endif
A virtual base class for objects that manage their own dynamic memory allocation.
Definition: AMReX_Arena.H:100
virtual void free(void *pt)=0
A pure virtual function for deleting the arena pointed to by pt.
virtual void * alloc(std::size_t sz)=0
Definition: AMReX_Amr.cpp:49
Arena * The_Arena()
Definition: AMReX_Arena.cpp:609
Definition: AMReX_DataAllocator.H:9
DataAllocator() noexcept=default
Arena * arena() const noexcept
Definition: AMReX_DataAllocator.H:24
void free(void *pt) const noexcept
Definition: AMReX_DataAllocator.H:20
Arena * m_arena
Definition: AMReX_DataAllocator.H:10
void * alloc(std::size_t sz) const noexcept
Definition: AMReX_DataAllocator.H:16
Definition: AMReX_DataAllocator.H:29
DataDeleter() noexcept=default
void operator()(void *pt) const noexcept
Definition: AMReX_DataAllocator.H:34
Arena * arena() const noexcept
Definition: AMReX_DataAllocator.H:33
Arena * m_arena
Definition: AMReX_DataAllocator.H:30