xo-interpreter2 .. xo-arena. memory pool introspection

This commit is contained in:
Roland Conybeare 2026-02-03 01:05:36 -05:00
commit 3c53d92735
6 changed files with 25 additions and 9 deletions

View file

@ -5,6 +5,7 @@
#pragma once
#include <xo/arena/MemorySizeInfo.hpp>
#include <xo/arena/AllocError.hpp>
#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*/

View file

@ -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<AAllocIterator> defn here

View file

@ -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);

View file

@ -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); }

View file

@ -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 **/

View file

@ -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