Mojo struct
ArcPointer
Atomic reference-counted pointer.
This smart pointer owns an instance of T
indirectly managed on the heap.
This pointer is copyable, including across threads, maintaining a reference
count to the underlying data.
This pointer itself is thread-safe using atomic accesses to reference count the underlying data, but references returned to the underlying data are not thread safe.
Parameters
- T (
Movable
): The type of the stored value.
Implemented traits
AnyType
,
CollectionElement
,
CollectionElementNew
,
Copyable
,
ExplicitlyCopyable
,
Identifiable
,
Movable
Methods
__init__
__init__(out self, owned value: T)
Construct a new thread-safe, reference-counted smart pointer, and move the value into heap memory managed by the new pointer.
Args:
- value (
T
): The value to manage.
__init__(out self, *, other: Self)
Copy the object.
Args:
- other (
Self
): The value to copy.
__copyinit__
__copyinit__(out self, existing: Self)
Copy an existing reference. Increment the refcount to the object.
Args:
- existing (
Self
): The existing reference.
__del__
__del__(owned self)
Delete the smart pointer reference.
Decrement the ref count for the reference. If there are no more references, delete the object and free its memory.
__getitem__
__getitem__[self_life: ImmutableOrigin](ref [self_life] self) -> ref [(mutcast $0)] T
Returns a mutable reference to the managed value.
Parameters:
- self_life (
ImmutableOrigin
): The origin of self.
Returns:
A reference to the managed value.
__is__
__is__(self, rhs: Self) -> Bool
Returns True if the two ArcPointers point at the same object.
Args:
- rhs (
Self
): The other ArcPointer.
Returns:
True if the two ArcPointers point at the same object and False otherwise.
__isnot__
__isnot__(self, rhs: Self) -> Bool
Returns True if the two ArcPointers point at different objects.
Args:
- rhs (
Self
): The other ArcPointer.
Returns:
True if the two ArcPointers point at different objects and False otherwise.
unsafe_ptr
unsafe_ptr(self) -> UnsafePointer[T]
Retrieves a pointer to the underlying memory.
Returns:
The UnsafePointer to the underlying memory.
count
count(self) -> SIMD[uint64, 1]
Count the amount of current references.
Returns:
The current amount of references to the pointee.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!