mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
Merge remote-tracking branch 'offical/master'
This commit is contained in:
+94
-3
@@ -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,
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -328,10 +328,24 @@ arena_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
|
||||
case size == 0:
|
||||
err = .Mode_Not_Implemented
|
||||
return
|
||||
case (uintptr(old_data) & uintptr(alignment-1) == 0) && size < old_size:
|
||||
// shrink data in-place
|
||||
data = old_data[:size]
|
||||
return
|
||||
case uintptr(old_data) & uintptr(alignment-1) == 0:
|
||||
if size < old_size {
|
||||
// shrink data in-place
|
||||
data = old_data[:size]
|
||||
return
|
||||
}
|
||||
|
||||
if block := arena.curr_block; block != nil {
|
||||
start := uint(uintptr(old_memory)) - uint(uintptr(block.base))
|
||||
old_end := start + old_size
|
||||
new_end := start + size
|
||||
if start < old_end && old_end == block.used && new_end <= block.reserved {
|
||||
// grow data in-place, adjusting next allocation
|
||||
_ = alloc_from_memory_block(block, new_end - old_end, 1, default_commit_size=arena.default_commit_size) or_return
|
||||
data = block.base[start:new_end]
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new_memory := arena_alloc(arena, size, alignment, location) or_return
|
||||
@@ -402,9 +416,10 @@ arena_temp_end :: proc(temp: Arena_Temp, loc := #caller_location) {
|
||||
|
||||
if block := arena.curr_block; block != nil {
|
||||
assert(block.used >= temp.used, "out of order use of arena_temp_end", loc)
|
||||
amount_to_zero := min(block.used-temp.used, block.reserved-block.used)
|
||||
amount_to_zero := block.used-temp.used
|
||||
mem.zero_slice(block.base[temp.used:][:amount_to_zero])
|
||||
block.used = temp.used
|
||||
arena.total_used -= amount_to_zero
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user