Sets the count of an array to new_count, growing the storage if needed.
Growth fills the new elements with the default value of T, unless $initialize is false, which leaves
them uninitialized. Shrinking only lowers the count and keeps the storage. For a view (a [] array
rather than a [..]) the storage is reallocated to exactly new_count elements through context.allocator,
and a count of 0 frees it and leaves an empty view. A negative new_count fails an assert.
values: [..] int;
array_resize(*values, 4);
assert(values.count == 4 && values[3] == 0);
array_resize(*values, 2);
assert(values.count == 2);
array_free(values);- initialize: set to
falseto leave new elements as the allocator returned them instead of setting them to their defaults.
array_resize :: (array: *[..] $T, new_count: s64, $initialize := true)
Sets the count of an array to new_count, growing the storage if needed.
Growth fills the new elements with the default value of T, unless $initialize is false, which leaves
them uninitialized. Shrinking only lowers the count and keeps the storage. For a view (a [] array
rather than a [..]) the storage is reallocated to exactly new_count elements through context.allocator,
and a count of 0 frees it and leaves an empty view. A negative new_count fails an assert.
Parameters
- array: *[..] $T
- new_count: s64
- $initialize := true
- set to
falseto leave new elements as the allocator returned them instead of setting them to their defaults.
values: [..] int;
array_resize(*values, 4);
assert(values.count == 4 && values[3] == 0);
array_resize(*values, 2);
assert(values.count == 2);
array_free(values);array_resize :: (array: *[] $T, new_count: s64, $initialize := true)
Resizes a view's storage to exactly new_count elements with context.allocator; see the first array_resize.
Parameters
- array: *[] $T
- new_count: s64
- $initialize := true