diff --git a/include/xo/object2/DArray.hpp b/include/xo/object2/DArray.hpp index f07941c..417318a 100644 --- a/include/xo/object2/DArray.hpp +++ b/include/xo/object2/DArray.hpp @@ -100,7 +100,12 @@ namespace xo { ///@} /** @defgroup darray-gcobject-methods **/ ///@{ - + /** shallow memory consumption. Excludes child objects **/ + AAllocator::size_type shallow_size() const noexcept; + /** return shallow copy of this array, using memory from @p mm **/ + DArray * shallow_copy(obj mm) const noexcept; + /** forward elements to @p gc to-space; replace originals with forarding pointers **/ + AAllocator::size_type forward_children(obj gc) noexcept; ///@} private: diff --git a/src/object2/DArray.cpp b/src/object2/DArray.cpp index 676086d..392404c 100644 --- a/src/object2/DArray.cpp +++ b/src/object2/DArray.cpp @@ -6,6 +6,7 @@ #include "DArray.hpp" #include #include +#include namespace xo { using xo::mm::AGCObject; @@ -64,5 +65,44 @@ namespace xo { return true; } } + + // gc hooks for IGCObject_DArray + + std::size_t + DArray::shallow_size() const noexcept + { + return sizeof(DArray); + } + + DArray * + DArray::shallow_copy(obj mm) const noexcept + { + DArray * copy = (DArray *)mm.alloc_copy((std::byte *)this); + + if (copy) { + copy->capacity_ = capacity_; + copy->size_ = size_; + + constexpr auto c_obj_z = sizeof(obj); + + /* memcpy sufficient for obj */ + ::memcpy((void*)&(copy->elts_[0]), (void*)&(elts_[0]), capacity_ * c_obj_z); + } + + return copy; + } + + std::size_t + DArray::forward_children(obj gc) noexcept + { + for (size_type i = 0; i < size_; ++i) { + obj & elt = elts_[i]; + + gc.forward_inplace(elt.iface(), (void **)&(elt.data_)); + } + + return shallow_size(); + } + } /*namespace scm*/ } /*namespace xo*/