diff --git a/include/xo/alloc2/alloc/AAllocator.hpp b/include/xo/alloc2/alloc/AAllocator.hpp index 588b439..4639d47 100644 --- a/include/xo/alloc2/alloc/AAllocator.hpp +++ b/include/xo/alloc2/alloc/AAllocator.hpp @@ -62,6 +62,10 @@ namespace xo { /** RTTI: unique id# for actual runtime data representation **/ virtual typeseq _typeseq() const noexcept = 0; + /** destroy instance @p d. Calls c++ destructor for actual runtime type. + * does not recover memory. + **/ + virtual void _drop(Opaque d) const noexcept = 0; /** optional name for allocator @p d . * Allows labeling allocators, for diagnostics/instrumentation. **/ @@ -142,10 +146,12 @@ 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 b45e765..aac80bc 100644 --- a/include/xo/alloc2/alloc/IAllocator_Any.hpp +++ b/include/xo/alloc2/alloc/IAllocator_Any.hpp @@ -32,7 +32,10 @@ namespace xo { const AAllocator * iface() const { return std::launder(this); } // from AAllocator + + // builtin methods typeseq _typeseq() const noexcept override { return s_typeseq; } + void _drop(Opaque) const noexcept override { _fatal(); } // const methods [[noreturn]] std::string_view name(Copaque) const noexcept override { _fatal(); } @@ -55,7 +58,6 @@ namespace xo { [[noreturn]] value_type sub_alloc(Opaque, std::size_t, bool) const override { _fatal(); } [[noreturn]] value_type alloc_copy(Opaque, value_type) const override { _fatal(); } [[noreturn]] void clear(Opaque) const override { _fatal(); } - [[noreturn]] void destruct_data(Opaque) const override { _fatal(); } private: [[noreturn]] static void _fatal(); diff --git a/include/xo/alloc2/alloc/IAllocator_Xfer.hpp b/include/xo/alloc2/alloc/IAllocator_Xfer.hpp index 790bcdc..e23d147 100644 --- a/include/xo/alloc2/alloc/IAllocator_Xfer.hpp +++ b/include/xo/alloc2/alloc/IAllocator_Xfer.hpp @@ -36,10 +36,14 @@ namespace xo { // from AAllocator - // const methods - + // builtin methods /** return typeseq for @tparam DRepr **/ 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)); } size_type reserved(Copaque d) const noexcept override { return I::reserved(_dcast(d)); } size_type size(Copaque d) const noexcept override { return I::size(_dcast(d)); } @@ -73,7 +77,6 @@ namespace xo { value_type alloc_copy(Opaque d, value_type src) const override { return I::alloc_copy(_dcast(d), src); } void clear(Opaque d) const override { return I::clear(_dcast(d)); } - void destruct_data(Opaque d) const override { return I::destruct_data(_dcast(d)); } ///@} private: diff --git a/include/xo/alloc2/alloc/RAllocator.hpp b/include/xo/alloc2/alloc/RAllocator.hpp index 2e9e7a8..c07b5e8 100644 --- a/include/xo/alloc2/alloc/RAllocator.hpp +++ b/include/xo/alloc2/alloc/RAllocator.hpp @@ -29,6 +29,7 @@ namespace xo { RAllocator(Object::DataPtr data) : Object{std::move(data)} {} typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); } + void _drop() const noexcept { O::iface()->_drop(O::data()); } std::string_view name() const noexcept { return O::iface()->name(O::data()); } size_type reserved() const noexcept { return O::iface()->reserved(O::data()); } size_type size() const noexcept { return O::iface()->size(O::data()); }