17 #ifndef ARENA_RESOURCE_HH_
18 #define ARENA_RESOURCE_HH_
20 #include <memory_resource>
31 template <
class Resource>
37 return std::pmr::null_memory_resource();
39 return std::pmr::get_default_resource();
47 buffer_(
std::pmr::get_default_resource()->allocate(buffer_size, simd_alignment) ),
82 size_t used_size = (
char *)p - (
char *)
buffer_;
92 size_t used_size = (
char *)p - (
char *)
buffer_;
94 std::cout <<
"Allocated space of arena is " << used_size <<
" B, free space is " << free_space <<
" B." << std::endl;
106 size_t bytes =
sizeof(T) * n_items;
113 size_t bytes =
sizeof(T) * n_items;
122 #ifdef FLOW123D_DEBUG
123 char *c_buffer = (
char *)
buffer_;
131 ASSERT(!
full_data_).error(
"Allocation of new data is not possible because child arena was created.");
134 void* p =
resource_.allocate(bytes, alignment);
135 used_size_ += (bytes + alignment - 1) / alignment * alignment;
137 throw std::bad_alloc();
153 bool do_is_equal(
const std::pmr::memory_resource& other)
const noexcept
override {
154 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())
Same as previous but doesn't construct buffer implicitly.