diff --git a/include/xo/alloc2/AllocHeaderConfig.hpp b/include/xo/alloc2/AllocHeaderConfig.hpp index 754a5c9..ab56088 100644 --- a/include/xo/alloc2/AllocHeaderConfig.hpp +++ b/include/xo/alloc2/AllocHeaderConfig.hpp @@ -6,6 +6,7 @@ #pragma once #include "AllocHeader.hpp" +#include "padding.hpp" #include namespace xo { @@ -121,6 +122,11 @@ namespace xo { return (hdr.repr_ & size_mask()); } + /** extract padded size from alloc header @p hdr **/ + std::size_t size_with_padding(repr_type hdr) const noexcept { + return padding::with_padding(this->size(hdr)); + } + /** true iff sentinel tseq, flagging a forwarding pointer **/ bool is_forwarding_tseq(repr_type hdr) const noexcept { // e.g. @@ -134,6 +140,11 @@ namespace xo { bool is_size_enabled() const noexcept { return size_bits_ > 0; } + /** construct alloc header for a forwarding object **/ + AllocHeader mark_forwarding_tseq(AllocHeader hdr) const noexcept { + return AllocHeader((hdr.repr_ & ~tseq_mask()) | tseq_mask()); + } + /** if non-zero, allocate extra space between allocs, and fill * with fixed test-pattern contents. Allows for simple * runtime arena sanitizing checks. diff --git a/include/xo/alloc2/AllocInfo.hpp b/include/xo/alloc2/AllocInfo.hpp index 0f8d0e1..30113e4 100644 --- a/include/xo/alloc2/AllocInfo.hpp +++ b/include/xo/alloc2/AllocInfo.hpp @@ -52,8 +52,15 @@ namespace xo { /** @defgroup mm-allocinfo-methods **/ ///@{ + AllocHeader header() const noexcept { return *p_header_; } + /** true for non-sentinel AllocInfo instance **/ - bool is_valid() const { return (p_config_ != nullptr) && (p_header_ != nullptr); } + bool is_valid() const noexcept { return ((p_config_ != nullptr) + && (p_header_ != nullptr)); } + /** true iff sentinel tseq, flagging a forwarding pointer **/ + bool is_forwarding_tseq() const noexcept { + return p_config_->is_forwarding_tseq(*p_header_); + } /** Guard bytes preceding allocation-header **/ span_type guard_lo() const noexcept; diff --git a/include/xo/alloc2/padding.hpp b/include/xo/alloc2/padding.hpp index 151d558..10d03b8 100644 --- a/include/xo/alloc2/padding.hpp +++ b/include/xo/alloc2/padding.hpp @@ -40,8 +40,6 @@ namespace xo { */ std::size_t dz = (align - (z % align)) % align; - z += dz; - return dz; }