Skip to main content

struct

Arc

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, Copyable, Movable

Methods

__init__

__init__(inout self: 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.

__copyinit__

__copyinit__(inout self: Self, existing: Self)

Copy an existing reference. Increment the refcount to the object.

Args:

  • existing (Self): The existing reference.

__del__

__del__(owned self: 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: Reference[Arc[T], is_mutable, lifetime, 0]) -> ref [$1] T

Returns a Reference to the managed value.

Returns:

A Reference to the managed value.

as_ptr

as_ptr(self: Self) -> UnsafePointer[T, 0]

Retrieves a pointer to the underlying memory.

Returns:

The UnsafePointer to the underlying memory.