xo-alloc / xo-ordinaltree: work on dual-alloc-policy trees

This commit is contained in:
Roland Conybeare 2025-12-02 10:37:07 -05:00
commit 62024de44f
3 changed files with 15 additions and 7 deletions

View file

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

View file

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

View file

@ -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<Allocator>::template object_interface<Allocator>
//
template <typename A, typename = void>
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 <typename A>
struct object_interface<A, std::void_t<typename A::gc_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<Allocator>::value;
};
} /*namespace gc*/
} /*namespace xo*/