Basic module

NewArray

procedureSource

Allocates count elements of T with context.allocator. They start as the default for T.

NewArray :: (
    count: s64,
    $T: Type,
    $initialized := true,
    alignment: s32 = -1
) -> (result: [] T, unaligned_base: *void)

The second result is the pointer the allocator gave out. Free that one, not result.data, which may have been moved forward to meet alignment.

Parameters

count: s64
$T: Type
$initialized := true
set to false to leave the elements as the allocator returned them.
alignment: s32 = -1
in bytes, a power of two. The type's own alignment when negative.

Returns

result: [] T
unaligned_base: *void
Example↗
numbers, base := NewArray(4, int);
defer free(base);
numbers[3] = 9;
assert(numbers.count == 4 && numbers[0] == 0);

See also