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