Mojo module
arc
Reference-counted smart pointers.
Example usage:
from memory import Arc
var p = Arc(4)
var p2 = p
p2[]=3
print(3 == p[])
from memory import Arc
var p = Arc(4)
var p2 = p
p2[]=3
print(3 == p[])
Subscripting([]
) is done by Reference
,
in order to ensure that the underlying Arc
outlive the operation.
It is highly DISCOURAGED to manipulate an Arc
through UnsafePointer
.
Mojo's ASAP deletion policy ensure values are destroyed at last use.
Do not unsafely dereference the Arc
inner UnsafePointer
field.
See Lifecycle.
# Illustration of what NOT to do, in order to understand:
print(Arc(String("ok"))._inner[].payload)
#........................^ASAP ^already freed
# Illustration of what NOT to do, in order to understand:
print(Arc(String("ok"))._inner[].payload)
#........................^ASAP ^already freed
Always use Reference
subscripting ([]
):
print(Arc(String("ok"))[])
print(Arc(String("ok"))[])
Structs
-
Arc
: Atomic reference-counted pointer.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!