jam 0.0.1
A compacting generational garbage collector for C++26
Loading...
Searching...
No Matches
jam::ptr< T > Class Template Referenceexport
Word heap | module jam

A typed heap offset, with no root registration or ownership. More...

Public Types

using element_type = T
 Target record type.
using offset = std::uint32_t
 Eight-byte cell index, stored in exactly four bytes.

Public Member Functions

constexpr ptr () noexcept=default
 Construct a null reference.
constexpr ptr (std::same_as< std::nullptr_t > auto) noexcept
 Implicitly construct a null pointer.
constexpr ptr (offset at) noexcept
 Name a record start in the matching heap; the caller supplies its type.
constexpr ptr (ptr const &other) noexcept
 Copy a pointer and register a young target when the destination is old.
template<class U>
requires (!std::same_as<T, U>) && std::derived_from<U, T> && detail::allocation_trace<T> && requires(T * p) { static_cast<U *>(p); }
constexpr ptr (ptr< U > const &other) noexcept
 Convert to a nonvirtual base with an allocation-tracing hook.
constexpr ptr (ptr &&other) noexcept
 Transfer the pointer and its source-slot registration, leaving other null.
constexpr ptr & operator= (ptr &&other) noexcept
 Transfer the pointer, leaving other null; self-move leaves it unchanged.
constexpr void swap (ptr &other) noexcept
 Exchange targets and update the remembered entries for both slots.
constexpr ~ptr () noexcept
 Remove a dying old pointer slot from the remembered set.
constexpr ptr & unsafe_assign (ptr const &other) noexcept
 Assign without a write barrier; the caller must register old-to-young edges.
constexpr ptr & unsafe_assign (offset bits) noexcept
 Install encoded bits without registration; the caller owns the barrier.
constexpr bool is_young () const noexcept
 Whether the target belongs to generation one.
constexpr offset local_offset () const noexcept
 Cell index within the target generation.
constexpr offset get () const noexcept
 Read the cell offset; unregistered copies expire on collection.
constexpr operator bool () const noexcept
 Whether the reference is nonnull.
T * operator-> () const noexcept
 Borrow the target in the current heap; expires on growth or collection.
T & operator* () const noexcept
 Borrow the target in the current heap.
void prefetch_marks () const noexcept
 Prefetch the target's mark metadata without claiming or reading it. Null does nothing, even without a current heap. Nonnull pointers must belong to the current heap. This cache hint provides no synchronization.
void prefetch () const noexcept
 Prefetch the cache line containing the target's first byte for reading. Null does nothing, even without a current heap. Nonnull pointers must belong to the current heap. No target is claimed or dereferenced.
constexpr auto operator<=> (ptr const &) const noexcept=default
 Order offsets within one heap; forwarding preserves surviving order. Compare fresh pointers after collection; unregistered copies still expire.

Friends

constexpr void swap (ptr &left, ptr &right) noexcept
 Exchange pointers through ADL, preserving each slot's write barrier.

Detailed Description

template<class T>
class jam::ptr< T >

A typed heap offset, with no root registration or ownership.

Template Parameters
TTarget record type; it may be incomplete here. No runtime type tag is stored. Null is zero. Copies preserve the offset; only declared heap fields and registered roots are forwarded. Using a pointer under a different heap is undefined behavior; pointers carry no owner ID. Outside the managed heap, do not retain a ptr for use across heap.collect(). Stack variables, external containers and loaded snapshots are not rewritten, even if a root keeps the target alive. Obtain a fresh pointer from that root after collection; only registered roots preserve external object identity.

Definition at line 570 of file heap.ccm.

Constructor & Destructor Documentation

◆ ptr()

template<class T>
requires (!std::same_as<T, U>) && std::derived_from<U, T> && detail::allocation_trace<T> && requires(T * p) { static_cast<U *>(p); }
template<class U>
requires (!std::same_as<T, U>) && std::derived_from<U, T> && detail::allocation_trace<T> && requires(T * p) { static_cast<U *>(p); }
jam::ptr< T >::ptr ( ptr< U > const & other)
inlineconstexprnoexcept

Convert to a nonvirtual base with an allocation-tracing hook.

Precondition
The base subobject shares the complete allocation's address.

Definition at line 2551 of file heap.ccm.

Member Function Documentation

◆ operator->()

template<class T>
T * jam::ptr< T >::operator-> ( ) const
inlinenodiscardnoexcept

Borrow the target in the current heap; expires on growth or collection.

Precondition
This nonnull pointer belongs to the current heap.

Definition at line 2588 of file heap.ccm.


The documentation for this class was generated from the following file: