17 #ifndef ARENA_RESOURCE_HH_
18 #define ARENA_RESOURCE_HH_
20 #include <memory_resource>
30 template <
class Resource>
49 return std::pmr::null_memory_resource();
51 return std::pmr::get_default_resource();
79 size_t used_size = (
char *)p - (
char *)
buffer_;
94 size_t bytes =
sizeof(T) * n_items;
101 size_t bytes =
sizeof(T) * n_items;
109 #ifdef FLOW123D_DEBUG
110 char *c_buffer = (
char *)
buffer_;
118 ASSERT(!
full_data_).error(
"Allocation of new data is not possible because child arena was created.");
120 void* p =
resource_.allocate(bytes, alignment);
121 used_size_ += (bytes + alignment - 1) / alignment * alignment;
123 throw std::bad_alloc();
139 bool do_is_equal(
const std::pmr::memory_resource& other)
const noexcept
override {
140 return this == &other;
ArenaResource< std::pmr::monotonic_buffer_resource > AssemblyArena
#define ASSERT_PERMANENT_EQ(a, b)
Definition of comparative assert macro (EQual)
Resource resource_
Resource of arena.
std::pmr::memory_resource * upstream_
Pointer to upstream.
T * allocate_8(size_t n_items)
Allocate and return data pointer of n_item array of type T (alignment to length 8 bytes)
ArenaResource(size_t buffer_size, size_t simd_alignment, std::pmr::memory_resource *upstream=ArenaResource< Resource >::upstream_resource())
void * do_allocate(size_t bytes, size_t alignment) override
Override do_allocate to handle allocation logic.
static std::pmr::memory_resource * upstream_resource()
Returns different upstream resource in debug / release mode.
bool full_data_
Flag signs full data (child arena is created)
T * allocate_simd(size_t n_items)
Allocate and return data pointer of n_item array of type T (alignment to length given by simd_alignme...
size_t used_size_
Temporary data member, will be removed.
void do_deallocate(FMT_UNUSED void *p, FMT_UNUSED size_t bytes, FMT_UNUSED size_t alignment) override
Override do_deallocate (no-op for monotonic buffer)
ArenaResource(void *buffer, size_t buffer_size, size_t simd_alignment)
Inner constructor, used only in construction of child arena.
bool do_is_equal(const std::pmr::memory_resource &other) const noexcept override
Override do_is_equal for memory resource comparison.
ArenaResource get_child_arena()
size_t buffer_size_
Size of buffer.
void * raw_allocate(size_t bytes, size_t alignment)
size_t simd_alignment_
Size of SIMD alignment.
void * buffer_
Pointer to buffer.
Resource & resource()
Getter for resource.