xo-object2: utest: ++ allocation in collector utest

This commit is contained in:
Roland Conybeare 2026-01-02 18:55:53 -05:00
commit 3f1470f938
18 changed files with 196 additions and 26 deletions

View file

@ -51,6 +51,19 @@ namespace xo {
age_bits_{a},
size_bits_{z} {}
/** create header tuple (@p t, @p a, @p z)
* with typeseq @p t, age @p a, size @p z
**/
std::uint64_t mkheader(std::uint64_t t,
std::uint64_t a,
std::uint64_t z) const noexcept {
uint64_t tseq_bits = (t << (age_bits_ + size_bits_)) & tseq_mask();
uint64_t age_bits = (a << size_bits_) & age_mask();
uint64_t size_bits = z & size_mask();;
return (tseq_bits | age_bits | size_bits);
}
std::uint64_t tseq_mask() const noexcept {
// e.g.
// FF FF FF 00 00 00 00 00

View file

@ -135,6 +135,11 @@ namespace xo {
* zero @p z.
**/
virtual value_type sub_alloc(Opaque d, size_type z, bool complete_flag) const = 0;
/** Allocate copy of an existing object @p src.
* Existing object must be contained in @p d.
* NOTE: load bearing for copying garbage collector.
**/
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;
/** Destruct allocator @p d.

View file

@ -53,6 +53,7 @@ namespace xo {
[[noreturn]] value_type alloc(Opaque, typeseq, std::size_t) const override { _fatal(); }
[[noreturn]] value_type super_alloc(Opaque, typeseq, std::size_t) const override { _fatal(); }
[[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(); }

View file

@ -70,6 +70,8 @@ namespace xo {
bool complete_flag) const override {
return I::sub_alloc(_dcast(d), z, complete_flag);
}
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)); }
///@}

View file

@ -45,6 +45,7 @@ namespace xo {
value_type sub_alloc(size_type z,
bool complete_flag) noexcept { return O::iface()->sub_alloc(O::data(),
z, complete_flag); }
value_type alloc_copy(value_type src) noexcept { return O::iface()->alloc_copy(O::data(), src); }
bool expand(size_type z) { return O::iface()->expand(O::data(), z); }
static bool _valid;

View file

@ -190,12 +190,18 @@ namespace xo {
**/
value_type sub_alloc(size_type z, bool complete_flag);
/** alloc copy of @p src **/
value_type alloc_copy(value_type src);
/** capture error information: advance error count + set last_error **/
void capture_error(error err,
size_type target_z = 0) const;
/** alloc driver. shared by alloc(), super_alloc(), sub_alloc() **/
value_type _alloc(std::size_t req_z, alloc_mode mode);
value_type _alloc(std::size_t req_z,
alloc_mode mode,
typeseq tseq,
uint32_t age);
/** expand committed space in arena @p d
* to size at least @p z

View file

@ -70,14 +70,10 @@ namespace xo {
* @p complete_flag to true.
**/
static value_type sub_alloc(DArena &, size_type z, bool complete_flag);
/** allocate copy of @p src in arena @p d. **/
static value_type alloc_copy(DArena & d, value_type src);
static void clear(DArena &);
static void destruct_data(DArena &);
private:
/** alloc driver. shared by alloc(), super_alloc(), sub_alloc() **/
static value_type _alloc(DArena &,
size_type z,
DArena::alloc_mode mode);
};
// template <>