xo-alloc: mutation log tracking in working state + unit test

This commit is contained in:
Roland Conybeare 2025-08-05 11:08:36 -05:00
commit c7488cbfd5
14 changed files with 659 additions and 94 deletions

View file

@ -12,6 +12,8 @@ namespace xo {
template <typename T>
using up = std::unique_ptr<T>;
class Object;
namespace gc {
/** @class IAllocator
* @brief memory allocation interface with limited garbaga collector support
@ -27,6 +29,8 @@ namespace xo {
/** z + alloc_padding(z) **/
static std::size_t with_padding(std::size_t z);
/** optional name for this allocator; labelling for diagnostics **/
virtual const std::string & name() const = 0;
/** allocator size in bytes (up to soft limit).
* Includes unallocated mmeory
**/
@ -47,15 +51,25 @@ namespace xo {
virtual std::size_t before_checkpoint() const = 0;
/** number of bytes allocated since @ref checkpoint **/
virtual std::size_t after_checkpoint() const = 0;
/** @return true iff debug logging enabled **/
virtual bool debug_flag() const { return false; }
/** reset allocator to empty state. **/
virtual void clear() = 0;
/** remember allocator state. All currently-allocated addresses x
/** remember allocator state. All currently-allocated addresses xo
* will satisfy is_before_checkpoint(x). Subsequent allocations x
* will fail is_before_checkpoint(x), until checkpoint superseded
* by @ref clear or another call to @ref checkpoint
**/
virtual void checkpoint() = 0;
/** perform assignment
* @code
* *lhs = rhs
* @endcode
* plus additional book keeping if needed (e.g. in @ref GC)
* Default implementation just does the assignment.
**/
virtual void assign_member(Object * parent, Object ** lhs, Object * rhs);
/** allocate @p z bytes of memory. returns pointer to first address **/
virtual std::byte * alloc(std::size_t z) = 0;
/** allocate @p z bytes for copy of object at @p src.