diff --git a/include/bitcoin/system/arena.hpp b/include/bitcoin/system/arena.hpp index 557be4f0d7..19e175112f 100644 --- a/include/bitcoin/system/arena.hpp +++ b/include/bitcoin/system/arena.hpp @@ -51,10 +51,17 @@ class arena return do_is_equal(other); } + /// Get the remaining area memory capacity (additional to std::pmr). + NODISCARD size_t get_capacity() const NOEXCEPT + { + return do_get_capacity(); + } + private: virtual void* do_allocate(size_t bytes, size_t align) THROWS = 0; virtual void do_deallocate(void* ptr, size_t bytes, size_t align) NOEXCEPT = 0; virtual bool do_is_equal(const arena& other) const NOEXCEPT = 0; + virtual size_t do_get_capacity() const NOEXCEPT = 0; }; /// Left can deallocate memory allocated by right and vice versa. @@ -84,6 +91,7 @@ class BC_API default_arena final void* do_allocate(size_t bytes, size_t align) THROWS override; void do_deallocate(void* ptr, size_t bytes, size_t align) NOEXCEPT override; bool do_is_equal(const arena& other) const NOEXCEPT override; + size_t do_get_capacity() const NOEXCEPT override; }; } // namespace libbitcoin diff --git a/src/arena.cpp b/src/arena.cpp index b922f73b4a..95e6c088f2 100644 --- a/src/arena.cpp +++ b/src/arena.cpp @@ -18,6 +18,8 @@ */ #include +#include + namespace libbitcoin { BC_PUSH_WARNING(NO_NEW_OR_DELETE) @@ -27,6 +29,14 @@ bool operator==(const arena& left, const arena& right) NOEXCEPT return &left == &right || left.is_equal(right); } +// static +// use bc::default_arena::get() vs. std::pmr::get_default_resource() +arena* default_arena::get() NOEXCEPT +{ + static default_arena resource{}; + return &resource; +} + void* default_arena::do_allocate(size_t bytes, size_t) THROWS { ////if (align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) @@ -49,11 +59,9 @@ bool default_arena::do_is_equal(const arena& other) const NOEXCEPT return &other == this; } -// use bc::default_arena::get() vs. std::pmr::get_default_resource() -arena* default_arena::get() NOEXCEPT +size_t default_arena::do_get_capacity() const NOEXCEPT { - static default_arena resource{}; - return &resource; + return max_size_t; } BC_POP_WARNING() diff --git a/test/test.hpp b/test/test.hpp index b262350faf..49ba03031e 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -157,6 +157,11 @@ class reporting_arena return &other == this; } + size_t do_get_capacity() const NOEXCEPT override + { + return {}; + } + void report(void* ptr, size_t bytes, bool allocate) const NOEXCEPT { if constexpr (Report) @@ -204,6 +209,11 @@ class mock_arena do_is_equal_address = &other; return false; } + + size_t do_get_capacity() const NOEXCEPT override + { + return {}; + } }; template