Basic module

array_reset_keeping_memory

procedure · 1 overloadSource

Empties the array but keeps its storage, so refilling it up to the old capacity allocates nothing.

The elements are not touched or destroyed; if they own memory, free that first.

ExampleOpen in playground ↗
values: [..] int;
array_add(*values, 1, 2, 3);
capacity := values.allocated;
array_reset_keeping_memory(*values);
assert(values.count == 0 && values.allocated == capacity);
array_free(values);
array_reset_keeping_memory :: (array: *[..] $T)

Empties the array but keeps its storage, so refilling it up to the old capacity allocates nothing.

The elements are not touched or destroyed; if they own memory, free that first.

Parameters

array: *[..] $T
ExampleOpen in playground ↗
values: [..] int;
array_add(*values, 1, 2, 3);
capacity := values.allocated;
array_reset_keeping_memory(*values);
assert(values.count == 0 && values.allocated == capacity);
array_free(values);

See also