A new array holding a copy of the elements, in memory from context.allocator.
The caller owns the copy and frees it with array_free. The elements are copied shallowly, so pointers
and strings in them still refer to the original data. With a destination, array_copy(*dest, source)
instead replaces the contents of the dynamic array dest, reusing its storage when that is large enough,
and the source may overlap dest.
original := int.[1, 2, 3];
copy := array_copy(original);
copy[0] = 100;
assert(original[0] == 1 && copy.count == 3);
array_free(copy);
list: [..] int;
array_copy(*list, original);
assert(list.count == 3 && list[2] == 3);
array_free(list);array_copy :: (array: [] $T) -> [] T
A new array holding a copy of the elements, in memory from context.allocator.
The caller owns the copy and frees it with array_free. The elements are copied shallowly, so pointers
and strings in them still refer to the original data. With a destination, array_copy(*dest, source)
instead replaces the contents of the dynamic array dest, reusing its storage when that is large enough,
and the source may overlap dest.
Parameters
- array: [] $T
Returns
- [] T
original := int.[1, 2, 3];
copy := array_copy(original);
copy[0] = 100;
assert(original[0] == 1 && copy.count == 3);
array_free(copy);
list: [..] int;
array_copy(*list, original);
assert(list.count == 3 && list[2] == 3);
array_free(list);array_copy :: (dest: *[..] $T, source: [] T)
Replaces the contents of dest with a copy of source; see the first array_copy.
Parameters
- dest: *[..] $T
- source: [] T