xo-alloc: UT for allocator interation + misc improvements
This commit is contained in:
parent
c7816416c5
commit
e454bee6af
10 changed files with 383 additions and 171 deletions
|
|
@ -46,9 +46,11 @@ namespace xo {
|
|||
public:
|
||||
virtual ~IAlloc() {}
|
||||
|
||||
/** word size for alignment **/
|
||||
static constexpr uint32_t c_alloc_alignment = sizeof(std::uintptr_t);
|
||||
|
||||
static inline std::uint32_t alloc_padding(std::size_t z) {
|
||||
/* word size for alignment */
|
||||
constexpr uint32_t c_bpw = sizeof(std::uintptr_t);
|
||||
constexpr uint32_t c_bpw = c_alloc_alignment;
|
||||
|
||||
/* round up to multiple of c_bpw, but map 0 -> 0
|
||||
* (table assuming c_bpw==8)
|
||||
|
|
|
|||
53
xo-allocutil/include/xo/allocutil/ObjectVisitor.hpp
Normal file
53
xo-allocutil/include/xo/allocutil/ObjectVisitor.hpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/** @file ObjectVisitor.hpp
|
||||
*
|
||||
**/
|
||||
|
||||
#include "IAlloc.hpp"
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace gc {
|
||||
/** @class ObjectVisitor
|
||||
* @brief visit IObject* members of a T instance
|
||||
*
|
||||
* Garbage collector relies on being able to navigate to
|
||||
* an IObject-instance to find+update embedded pointers to
|
||||
* other IObjects.
|
||||
*
|
||||
* An IObject implemnetation must override
|
||||
* IObject::_forward_children(IAlloc * gc)
|
||||
* and call
|
||||
* gc->forward_inplace(&child_)
|
||||
* for each such child pointer.
|
||||
*
|
||||
* For non-template classes this is straightforward
|
||||
* See for example
|
||||
* xo::obj::List in object/List.hpp
|
||||
*
|
||||
* For a template class Foo<T> that contains T-instances,
|
||||
* need to handle case where T contains IObject pointers.
|
||||
* See for example the
|
||||
* xo::tree::RedBlackTree in ordinaltree/RedBlackTree.hpp
|
||||
*
|
||||
* Use ObjectVisitor<T>::forward_children() to pick up
|
||||
* navigation code for such template arguments.
|
||||
**/
|
||||
template <typename T>
|
||||
class ObjectVisitor {
|
||||
//void forward_children(T & target, IAlloc * gc) { (void)target; (void)gc; }
|
||||
};
|
||||
|
||||
#define XO_TRIVIAL_OBJECT_VISITOR(TYPE) \
|
||||
template <> \
|
||||
class ObjectVisitor<TYPE> { \
|
||||
public: \
|
||||
static void forward_children(TYPE &, IAlloc *) {} \
|
||||
}
|
||||
|
||||
XO_TRIVIAL_OBJECT_VISITOR(int32_t);
|
||||
XO_TRIVIAL_OBJECT_VISITOR(double);
|
||||
|
||||
} /*namespace gc*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* ObjectVisitor.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue