Browse Source

Merge pull request #4698 from 4teapo/mem-additions

Add SoA make/delete to core:mem
gingerBill 7 months ago
parent
commit
ed18f539c7
1 changed files with 94 additions and 3 deletions
  1. 94 3
      core/mem/alloc.odin

+ 94 - 3
core/mem/alloc.odin

@@ -785,6 +785,27 @@ delete_map :: proc(
 	return runtime.delete_map(m, loc)
 }
 
+/*
+Free an SoA slice.
+*/
+delete_soa_slice :: proc(
+	array: $T/#soa[]$E,
+	allocator := context.allocator,
+	loc := #caller_location,
+) -> Allocator_Error {
+	return runtime.delete_soa_slice(array, allocator, loc)
+}
+
+/*
+Free an SoA dynamic array.
+*/
+delete_soa_dynamic_array :: proc(
+	array: $T/#soa[dynamic]$E,
+	loc := #caller_location,
+) -> Allocator_Error {
+	return runtime.delete_soa_dynamic_array(array, loc)
+}
+
 /*
 Free.
 */
@@ -794,6 +815,8 @@ delete :: proc{
 	delete_dynamic_array,
 	delete_slice,
 	delete_map,
+	delete_soa_slice,
+	delete_soa_dynamic_array,
 }
 
 /*
@@ -900,8 +923,7 @@ make_dynamic_array :: proc(
 Allocate a dynamic array with initial length.
 
 This procedure creates a dynamic array of type `T`, with `allocator` as its
-backing allocator, and initial capacity of `0`, and initial length specified by
-`len`.
+backing allocator, and initial capacity and length specified by `len`.
 */
 @(require_results)
 make_dynamic_array_len :: proc(
@@ -910,7 +932,7 @@ make_dynamic_array_len :: proc(
 	allocator := context.allocator,
 	loc := #caller_location,
 ) -> (T, Allocator_Error) {
-	return runtime.make_dynamic_array_len_cap(T, len, len, allocator, loc)
+	return runtime.make_dynamic_array_len(T, len, allocator, loc)
 }
 
 /*
@@ -964,6 +986,71 @@ make_multi_pointer :: proc(
 	return runtime.make_multi_pointer(T, len, allocator, loc)
 }
 
+/*
+Allocate an SoA slice.
+
+This procedure allocates an SoA slice of type `T` with length `len`, from an
+allocator specified by `allocator`, and returns the allocated SoA slice.
+*/
+@(require_results)
+make_soa_slice :: proc(
+	$T: typeid/#soa[]$E,
+	#any_int len: int,
+	allocator := context.allocator,
+	loc := #caller_location
+) -> (array: T, err: Allocator_Error) {
+	return runtime.make_soa_slice(T, len, allocator, loc)
+}
+
+/*
+Allocate an SoA dynamic array.
+
+This procedure creates an SoA dynamic array of type `T`, with `allocator` as
+its backing allocator, and initial length and capacity of `0`.
+*/
+@(require_results)
+make_soa_dynamic_array :: proc(
+	$T: typeid/#soa[dynamic]$E,
+	allocator := context.allocator,
+	loc := #caller_location
+) -> (array: T, err: Allocator_Error) {
+	return runtime.make_soa_dynamic_array(T, allocator, loc)
+}
+
+/*
+Allocate an SoA dynamic array with initial length.
+
+This procedure creates an SoA dynamic array of type `T`, with `allocator` as its
+backing allocator, and initial capacity and length specified by `len`.
+*/
+@(require_results)
+make_soa_dynamic_array_len :: proc(
+	$T: typeid/#soa[dynamic]$E,
+	#any_int len: int,
+	allocator := context.allocator,
+	loc := #caller_location
+) -> (array: T, err: Allocator_Error) {
+	return runtime.make_soa_dynamic_array_len(T, len, allocator, loc)
+}
+
+/*
+Allocate an SoA dynamic array with initial length and capacity.
+
+This procedure creates an SoA dynamic array of type `T`, with `allocator` as its
+backing allocator, and initial capacity specified by `cap`, and initial length
+specified by `len`.
+*/
+@(require_results)
+make_soa_dynamic_array_len_cap :: proc(
+	$T: typeid/#soa[dynamic]$E,
+	#any_int len: int,
+	#any_int cap: int,
+	allocator := context.allocator,
+	loc := #caller_location
+) -> (array: T, err: Allocator_Error) {
+	return runtime.make_soa_dynamic_array_len_cap(T, len, cap, allocator, loc)
+}
+
 /*
 Allocate.
 */
@@ -974,6 +1061,10 @@ make :: proc{
 	make_dynamic_array_len_cap,
 	make_map,
 	make_multi_pointer,
+	make_soa_slice,
+	make_soa_dynamic_array,
+	make_soa_dynamic_array_len,
+	make_soa_dynamic_array_len_cap,
 }
 
 /*