From d9f38d854cbd9a0c81c19c1bd0382d8d637bf08b Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sun, 18 Aug 2024 16:26:44 -0400 Subject: [PATCH] Modify arena custom interface for detachment. --- include/bitcoin/system/arena.hpp | 20 ++++++++++++++++---- src/arena.cpp | 11 ++++++++++- test/test.hpp | 22 ++++++++++++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/include/bitcoin/system/arena.hpp b/include/bitcoin/system/arena.hpp index 54cd2413d2..68ce919331 100644 --- a/include/bitcoin/system/arena.hpp +++ b/include/bitcoin/system/arena.hpp @@ -51,9 +51,19 @@ class arena return do_is_equal(other); } - /// Non-linear allocator is a nop and returns nullptr. - /// Reset linear allocator and return starting address (not pmr interface). - virtual void* initialize() NOEXCEPT = 0; + /// Non-linear allocator just returns next address. + /// Linear allocator resets to and returns buffer first address. + /// Detachable linear allocator allocates buffer returns its first address. + virtual void* start() NOEXCEPT = 0; + + /// Non-linear allocator just returns zero. + /// Linear allocator returns current allocation size. + /// Detachable linear allocator detaches allocation and returns its size. + virtual size_t detach() NOEXCEPT = 0; + + /// Non-linear and linear allocator is a nop. + /// Detachable linear allocator frees the memory associated with ptr. + virtual void release(void* ptr, size_t bytes) NOEXCEPT = 0; private: virtual void* do_allocate(size_t bytes, size_t align) THROWS = 0; @@ -83,7 +93,9 @@ class BC_API default_arena final { public: static arena* get() NOEXCEPT; - void* initialize() NOEXCEPT override; + void* start() NOEXCEPT override; + size_t detach() NOEXCEPT override; + void release(void* ptr, size_t bytes) NOEXCEPT override; private: void* do_allocate(size_t bytes, size_t align) THROWS override; diff --git a/src/arena.cpp b/src/arena.cpp index 89b41d7df5..3ae19bbbea 100644 --- a/src/arena.cpp +++ b/src/arena.cpp @@ -57,11 +57,20 @@ bool default_arena::do_is_equal(const arena& other) const NOEXCEPT return &other == this; } -void* default_arena::initialize() NOEXCEPT +void* default_arena::start() NOEXCEPT { return nullptr; } +size_t default_arena::detach() NOEXCEPT +{ + return zero; +} + +void default_arena::release(void*, size_t) NOEXCEPT +{ +} + BC_POP_WARNING() } // namespace libbitcoin diff --git a/test/test.hpp b/test/test.hpp index ee10f8a291..149c94ce18 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -127,11 +127,20 @@ class reporting_arena size_t dec_count{}; size_t dec_bytes{}; - void* initialize() NOEXCEPT override + void* start() NOEXCEPT override { return nullptr; } + size_t detach() NOEXCEPT override + { + return zero; + } + + void release(void*, size_t) NOEXCEPT override + { + } + private: void* do_allocate(size_t bytes, size_t align) override { @@ -189,11 +198,20 @@ class mock_arena size_t do_deallocate_align{}; mutable const arena* do_is_equal_address{}; - void* initialize() NOEXCEPT override + void* start() NOEXCEPT override { return nullptr; } + size_t detach() NOEXCEPT override + { + return zero; + } + + void release(void*, size_t) NOEXCEPT override + { + } + private: void* do_allocate(size_t bytes, size_t align) THROWS override {