Version: 1.1.0
Using pointers
Using a pointer means allocating, initializing, indexing, and freeing in matching pairs.
Essentials
alloc<a href="/n/">T</a>reserves room fornvalues.- Store a value with
ptr.init_pointee_moveor assignment when the memory is already live. - Pointer arithmetic steps in units of
T, not bytes. bitcastreinterprets the address. It does not convert the value.- Never free a pointer you did not allocate, and never free it twice.
Example
fn fill(ptr: UnsafePointer[Int], n: Int):
for i in range(n):
ptr[i] = i
Keep in mind
Pass a Span across function boundaries when the length matters. A bare pointer forgets how much memory is live.