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();
59 buffer_(
std::pmr::get_default_resource()->allocate(buffer_size, simd_alignment) ),
80 size_t used_size = (
char *)p - (
char *)
buffer_;
90 size_t used_size = (
char *)p - (
char *)
buffer_;
92 std::cout <<
"Allocated space of arena is " << used_size <<
" B, free space is " << free_space <<
" B." << std::endl;
104 size_t bytes =
sizeof(T) * n_items;
111 size_t bytes =
sizeof(T) * n_items;
120 #ifdef FLOW123D_DEBUG
121 char *c_buffer = (
char *)
buffer_;
129 ASSERT(!
full_data_).error(
"Allocation of new data is not possible because child arena was created.");
132 void* p =
resource_.allocate(bytes, alignment);
133 used_size_ += (bytes + alignment - 1) / alignment * alignment;
135 throw std::bad_alloc();
151 bool do_is_equal(
const std::pmr::memory_resource& other)
const noexcept
override {
152 return this == &other;
ArenaResource< std::pmr::monotonic_buffer_resource > AssemblyArena
#define ASSERT_PERMANENT_EQ(a, b)
Definition of comparative assert macro (EQual)
#define ASSERT_EQ(a, b)
Definition of comparative assert macro (EQual) only for debug mode.
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())
Constructor. Creates assembly arena.
void print_space()
Compute and print free space and used space of arena buffer. Development method.
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)
bool do_is_equal(const std::pmr::memory_resource &other) const noexcept override
Override do_is_equal for memory resource comparison.
size_t buffer_size_
Size of buffer.
ArenaResource * get_child_arena()
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.
ArenaResource(void *buffer, size_t buffer_size, size_t simd_alignment, std::pmr::memory_resource *upstream=ArenaResource< Resource >::upstream_resource())
Inner constructor, used only in construction of child arena.