diff --git a/include/xo/alloc2/alloc/AAllocator.hpp b/include/xo/alloc2/alloc/AAllocator.hpp index 4639d47..ecc5286 100644 --- a/include/xo/alloc2/alloc/AAllocator.hpp +++ b/include/xo/alloc2/alloc/AAllocator.hpp @@ -5,6 +5,7 @@ #pragma once +#include #include #include "AllocInfo.hpp" //#include "AllocIterator.hpp" @@ -33,9 +34,11 @@ namespace xo { struct AAllocator { /** @defgroup mm-allocator-type-traits allocator type traits **/ ///@{ - /** @brief type used for allocation amounts **/ + /** memory size report **/ + using MemorySizeInfo = xo::mm::MemorySizeInfo; + /** type used for allocation amounts **/ using size_type = std::size_t; - /** @brief type used for allocation responses **/ + /** type used for allocation responses **/ using value_type = std::byte *; /** object header, if configured **/ using header_type = std::uint64_t; @@ -95,6 +98,12 @@ namespace xo { * Includes alloc headers and guard regions **/ virtual size_type allocated(Copaque d) const noexcept = 0; + /** call @p fn(i,n,info) for each memory pool owned by this allocator. + * Note: using std::function instead of obj<> to avoid leveling trouble + * with DArena + **/ + virtual void visit_pools(Copaque d, + const MemorySizeVisitor & fn) const = 0; /** true iff allocator @p d is responsible for memory at address @p p. **/ virtual bool contains(Copaque d, const void * p) const noexcept = 0; @@ -146,12 +155,6 @@ namespace xo { virtual value_type alloc_copy(Opaque d, value_type src) const = 0; /** reset allocator @p d to empty state. **/ virtual void clear(Opaque d) const = 0; -#ifdef OBSOLETE - /** Destruct allocator @p d. - * Releases allocator memory to operating system. - **/ - virtual void destruct_data(Opaque d) const = 0; -#endif ///@} }; /*AAllocator*/ diff --git a/include/xo/alloc2/alloc/IAllocator_Any.hpp b/include/xo/alloc2/alloc/IAllocator_Any.hpp index aac80bc..fa8c14a 100644 --- a/include/xo/alloc2/alloc/IAllocator_Any.hpp +++ b/include/xo/alloc2/alloc/IAllocator_Any.hpp @@ -45,6 +45,8 @@ namespace xo { [[noreturn]] size_type available(Copaque) const noexcept override { _fatal(); } [[noreturn]] size_type allocated(Copaque) const noexcept override { _fatal(); } [[noreturn]] bool contains(Copaque, const void *) const noexcept override { _fatal(); } + [[noreturn]] void visit_pools(Copaque, + const MemorySizeVisitor &) const override { _fatal(); } [[noreturn]] AllocError last_error(Copaque) const noexcept override { _fatal(); } [[noreturn]] AllocInfo alloc_info(Copaque, value_type) const noexcept override { _fatal(); } // defn in .cpp - problematic to require compiler know vt defn here diff --git a/include/xo/alloc2/alloc/IAllocator_Xfer.hpp b/include/xo/alloc2/alloc/IAllocator_Xfer.hpp index e23d147..e5b539a 100644 --- a/include/xo/alloc2/alloc/IAllocator_Xfer.hpp +++ b/include/xo/alloc2/alloc/IAllocator_Xfer.hpp @@ -41,7 +41,7 @@ namespace xo { typeseq _typeseq() const noexcept override { return s_typeseq; } /** invoke native c++ dtor **/ void _drop(Opaque d) const noexcept override { _dcast(d).~DRepr(); } - + // const methods std::string_view name(Copaque d) const noexcept override { return I::name(_dcast(d)); } @@ -53,6 +53,7 @@ namespace xo { bool contains(Copaque d, const void * p) const noexcept override { return I::contains(_dcast(d), p); } + void visit_pools(Copaque d, const MemorySizeVisitor & fn) const override { I::visit_pools(_dcast(d), fn); } AllocError last_error(Copaque d) const noexcept override { return I::last_error(_dcast(d)); } AllocInfo alloc_info(Copaque d, value_type mem) const noexcept override { return I::alloc_info(_dcast(d), mem); diff --git a/include/xo/alloc2/alloc/RAllocator.hpp b/include/xo/alloc2/alloc/RAllocator.hpp index bbd35d5..ad528ba 100644 --- a/include/xo/alloc2/alloc/RAllocator.hpp +++ b/include/xo/alloc2/alloc/RAllocator.hpp @@ -39,6 +39,7 @@ namespace xo { size_type committed() const noexcept { return O::iface()->committed(O::data()); } size_type available() const noexcept { return O::iface()->available(O::data()); } size_type allocated() const noexcept { return O::iface()->allocated(O::data()); } + void visit_pools(const MemorySizeVisitor & fn) const { O::iface()->visit_pools(O::data(), fn); } bool contains(const void * p) const noexcept { return O::iface()->contains(O::data(), p); } AllocError last_error() const noexcept { return O::iface()->last_error(O::data()); } AllocInfo alloc_info(value_type mem) const noexcept { return O::iface()->alloc_info(O::data(), mem); } diff --git a/include/xo/alloc2/arena/IAllocator_DArena.hpp b/include/xo/alloc2/arena/IAllocator_DArena.hpp index 4a87182..81e9221 100644 --- a/include/xo/alloc2/arena/IAllocator_DArena.hpp +++ b/include/xo/alloc2/arena/IAllocator_DArena.hpp @@ -40,6 +40,8 @@ namespace xo { static size_type committed(const DArena &) noexcept; static size_type available(const DArena &) noexcept; static size_type allocated(const DArena &) noexcept; + static void visit_pools(const DArena &, + const MemorySizeVisitor & visitor); static bool contains(const DArena &, const void * p) noexcept; static AllocError last_error(const DArena &) noexcept; /** retrieve allocation bookkeeping info for @p mem from arena @p d **/ diff --git a/src/alloc2/IAllocator_DArena.cpp b/src/alloc2/IAllocator_DArena.cpp index a3bd961..2a3a2d5 100644 --- a/src/alloc2/IAllocator_DArena.cpp +++ b/src/alloc2/IAllocator_DArena.cpp @@ -52,6 +52,13 @@ namespace xo { return s.allocated(); } + void + IAllocator_DArena::visit_pools(const DArena & s, + const MemorySizeVisitor & visitor) + { + s.visit_pools(visitor); + } + bool IAllocator_DArena::contains(const DArena & s, const void * p) noexcept