Basic module

New

procedureSource

Allocates a T with context.allocator and returns a pointer to it. The value starts as the default for T. Free it with free.

New :: ($T: Type, $initialized := true) -> *T

Parameters

$T: Type
$initialized := true
set to false to skip setting the default; the bytes are then whatever the allocator returned.

Returns

*T
Example↗
Point :: struct { x := 1; y := 2; }
p := New(Point);
defer free(p);
assert(p.x == 1 && p.y == 2);

See also