From 62024de44fcb9070c07f2944214afd21d3b9ba0c Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 2 Dec 2025 10:37:07 -0500 Subject: [PATCH] xo-alloc / xo-ordinaltree: work on dual-alloc-policy trees --- include/xo/allocutil/IAlloc.hpp | 6 ++++-- include/xo/allocutil/IObject.hpp | 3 +++ include/xo/allocutil/gc_allocator_traits.hpp | 13 ++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/xo/allocutil/IAlloc.hpp b/include/xo/allocutil/IAlloc.hpp index 4f9097f..a322e1d 100644 --- a/include/xo/allocutil/IAlloc.hpp +++ b/include/xo/allocutil/IAlloc.hpp @@ -76,7 +76,7 @@ namespace xo { std::byte * allocate(std::size_t n) { return this->alloc(n); } - + /** std::allocator locality hint. Not used for now **/ std::byte * allocate(std::size_t n, const void * hint) { (void)hint; @@ -147,6 +147,8 @@ namespace xo { virtual void assign_member(IObject * /*parent*/, IObject ** lhs, IObject * rhs) { *lhs = rhs; } + /** if GC: evacuate @p *lhs and replace with forwarding pointer **/ + virtual void forward_inplace(IObject ** lhs) { (void)lhs; } /** allocate @p z bytes for copy of object at @p src. * Only used in @ref GC. Default implementation asserts and returns nullptr **/ @@ -170,7 +172,7 @@ namespace xo { using const_reference = const T &; using size_type = IAlloc::size_type; using difference_type = std::ptrdiff_t; - + using gc_object_interface = IAlloc::gc_object_interface; using has_incremental_gc_interface = IAlloc::has_incremental_gc_interface; diff --git a/include/xo/allocutil/IObject.hpp b/include/xo/allocutil/IObject.hpp index 87c6013..2104888 100644 --- a/include/xo/allocutil/IObject.hpp +++ b/include/xo/allocutil/IObject.hpp @@ -19,6 +19,9 @@ namespace xo { **/ class IObject { public: + /** impl inheriting this class must provide gc hooks **/ + static constexpr bool _requires_gc_hooks = true; + /** true iff this object represents a forwarding pointer. * Forwarding pointers are exclusively created by the garbage collector; * forwarding pointers (and only forwarding pointers) return true here. diff --git a/include/xo/allocutil/gc_allocator_traits.hpp b/include/xo/allocutil/gc_allocator_traits.hpp index dd1a632..38e7f38 100644 --- a/include/xo/allocutil/gc_allocator_traits.hpp +++ b/include/xo/allocutil/gc_allocator_traits.hpp @@ -32,7 +32,7 @@ namespace xo { * provide garbage collection * - xo::gc::GC has a collection API and also provides * garbage collection - * + * * GC-allocated objects must: * 2a. inherit A::object_interface * 2b. implement A::object_interface::_shallow_size() @@ -40,7 +40,7 @@ namespace xo { * 2d. implement A::object_interface::_forward_children(alloc) * in multiple inheritance scenarios * 2e. implement A::object_interface::_offset_destination(src) - * + * * Design Notes: * - virtual-method choice requires vtable pointer per object; * but zero *marginal* space cost for types that would have @@ -82,12 +82,16 @@ namespace xo { // gc_allocator_traits::template object_interface // template - struct object_interface {}; + struct object_interface { + /** see also IObject::_requires_gc_hooks **/ + static constexpr bool _requires_gc_hooks = false; + }; // specialization when A provides gc_object_interface template struct object_interface> - : A::gc_object_interface {}; + : public A::gc_object_interface { + }; /** true iff this allocator advertises itself as an incremental collector * allocator will include: @@ -97,7 +101,6 @@ namespace xo { * }; **/ static inline constexpr bool has_incremental_gc_interface_v = has_incremental_gc_interface::value; - }; } /*namespace gc*/ } /*namespace xo*/