Skip to content

Commit d46d4d5

Browse files
committed
[api] Add make_temporary_array helper.
1 parent 0f8749d commit d46d4d5

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

CHANGELOG.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ std/sync:
101101
std/static_array:
102102
- Add `sarray_pop_first` and `sarray_erase_keep_order`.
103103

104+
std/array
105+
- Add `make_temporary_array`.
106+
104107
[Documentation]
105108
- Add documentation for comptime call.
106109
- Add documentation for static if.

lib/bl/api/std/array/array.bl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ array_terminate :: fn (_arr: *[..]?T) #inline {
8181
arr.allocated_elems = 0;
8282
}
8383

84+
/// Returns new dynamic array `[..]TElem` initialized to use current `application_context.temporary_allocator`.
85+
/// The `expected_element_count` can be used to preallocate elements in advance.
86+
make_temporary_array :: fn (TElem: type #comptime, expected_element_count: s64 = 0) [..]TElem #inline {
87+
arr: [..]TElem;
88+
array_init(&arr, expected_element_count, application_context.temporary_allocator);
89+
return arr;
90+
}
91+
8492
/// Append new value at the dynamic array end. New heap allocation is done here only in cases when
8593
/// there is not enough memory allocated to store all values.
8694
/// Returns pointer to the new appended element.

0 commit comments

Comments
 (0)