pub struct GcPtr<T> { /* private fields */ }Expand description
A pointer to a GC-managed object of type T.
The object is laid out in memory as:
[GcHeader (8 bytes)][T data (size bytes)]
^--- GcPtr points hereGcPtr is Copy — no refcount manipulation. The GC is solely responsible for determining liveness and reclaiming memory.
Implementations§
Source§impl<T> GcPtr<T>
impl<T> GcPtr<T>
Sourcepub unsafe fn from_raw(ptr: *mut T) -> Self
pub unsafe fn from_raw(ptr: *mut T) -> Self
Create a GcPtr from a raw pointer.
§Safety
The pointer must point to a valid T preceded by a GcHeader at ptr - 8.
Sourcepub fn header(self) -> &'static GcHeader
pub fn header(self) -> &'static GcHeader
Get a reference to the GcHeader preceding this object.
Sourcepub unsafe fn header_mut(self) -> &'static mut GcHeader
pub unsafe fn header_mut(self) -> &'static mut GcHeader
Get a mutable reference to the GcHeader preceding this object.
§Safety
Caller must ensure exclusive access to the header.
Sourcepub unsafe fn deref_gc(self) -> &'static T
pub unsafe fn deref_gc(self) -> &'static T
Dereference to get a reference to the managed object.
§Safety
The object must still be alive (not collected).
Sourcepub unsafe fn deref_gc_mut(self) -> &'static mut T
pub unsafe fn deref_gc_mut(self) -> &'static mut T
Dereference to get a mutable reference to the managed object.
§Safety
The object must still be alive and caller must have exclusive access.
Sourcepub fn with_mark_bit(self) -> Self
pub fn with_mark_bit(self) -> Self
Set the inline mark bit (x86-64: use LAM if available, else no-op).
Sourcepub fn clear_mark_bit(self) -> Self
pub fn clear_mark_bit(self) -> Self
Clear the inline mark bit (x86-64: use LAM if available, else no-op).
Sourcepub fn has_mark_bit(self) -> bool
pub fn has_mark_bit(self) -> bool
Check whether the inline mark bit is set (x86-64: use LAM if available).
Sourcepub fn is_marked(self) -> bool
pub fn is_marked(self) -> bool
Check the mark state, combining inline pointer bits with the GcHeader side table for a definitive answer on any platform.
Returns true if either the inline mark bit is set (on HW-masking
platforms) or the GcHeader color is Gray/Black.
Sourcepub fn raw_ptr(self) -> *mut T
pub fn raw_ptr(self) -> *mut T
Strip all metadata bits from the pointer, returning the raw address.
Uses the detected masking mode to apply the correct mask.
Sourcepub fn as_untyped(self) -> *mut u8
pub fn as_untyped(self) -> *mut u8
Convert to an untyped pointer for use in the root set / marker.
Sourcepub unsafe fn from_untyped(ptr: *mut u8) -> Self
pub unsafe fn from_untyped(ptr: *mut u8) -> Self
Create from an untyped pointer.
§Safety
The pointer must actually point to a valid T with GcHeader prefix.