diff --git a/include/xo/allocutil/IAlloc.hpp b/include/xo/allocutil/IAlloc.hpp index b126d8a..703e968 100644 --- a/include/xo/allocutil/IAlloc.hpp +++ b/include/xo/allocutil/IAlloc.hpp @@ -42,6 +42,7 @@ namespace xo { **/ using gc_object_interface = xo::Object; using has_incremental_gc_interface = std::true_type; + using has_trivial_deallocate = std::true_type; public: virtual ~IAlloc() {} diff --git a/include/xo/allocutil/gc_allocator_traits.hpp b/include/xo/allocutil/gc_allocator_traits.hpp index 30cbb4f..80184b0 100644 --- a/include/xo/allocutil/gc_allocator_traits.hpp +++ b/include/xo/allocutil/gc_allocator_traits.hpp @@ -74,7 +74,20 @@ namespace xo { struct has_incremental_gc_interface> : A::has_incremental_gc_interface {}; + // default: allocate A fallback to standard non-GC allocator behavior + template + struct has_trivial_deallocate : std::false_type {}; + + // opt-in: A provides nested type 'has_trivial_deallocate': + // struct A { + // using has_trivial_deallocate = std::true_type; + // }; + template + struct has_trivial_deallocate> : + A::has_trivial_deallocate {}; + // default: empty object interface. + // // classes that want to conditionally support GC // (e.g. see xo::tree::RedBlackTree, xo::tree::Node // in xo-ordinal-tree) @@ -85,13 +98,24 @@ namespace xo { struct object_interface { /** see also IObject::_requires_gc_hooks **/ static constexpr bool _requires_gc_hooks = false; + /** see also IObject::_requires_write_barrier **/ + static constexpr bool _requires_write_barrier = false; + + /** see also IObject::_gc_assign_member **/ + template + void _gc_assign_member(T ** lhs, + T * rhs, + A & alloc) + { + *lhs = rhs; + } + }; // specialization when A provides gc_object_interface template struct object_interface> - : public A::gc_object_interface { - }; + : public A::gc_object_interface {}; // classes that want to conditionally support GC // (e.g. see xo::tree::RedBlackTree, xo::tree::Node @@ -101,14 +125,23 @@ namespace xo { // using object_interface_type = object_interface; - /** true iff this allocator advertises itself as an incremental collector - * allocator will include: + /** true iff this allocator advertises itself as an incremental collector. + * Allocator will include: * - * struct GC { + * struct IAlloc { * using has_incremental_gc_interface = std::true_type; * }; **/ static inline constexpr bool has_incremental_gc_interface_v = has_incremental_gc_interface::value; + + /** true iff this allocator advertises trivial deallocate + * Allocate will include: + * + * struct IAlloc { + * using has_trivial_deallocate = std::true_type; + * }; + **/ + static inline constexpr bool has_trivial_deallocate_v = has_trivial_deallocate::value; }; } /*namespace gc*/ } /*namespace xo*/