mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Add default_temp_allocator_temp_begin and default_temp_allocator_temp_end
This commit is contained in:
@@ -11,6 +11,14 @@ when ODIN_OS == .Freestanding || ODIN_OS == .JS || ODIN_DEFAULT_TO_NIL_ALLOCATOR
|
|||||||
default_temp_allocator_destroy :: proc(s: ^Default_Temp_Allocator) {}
|
default_temp_allocator_destroy :: proc(s: ^Default_Temp_Allocator) {}
|
||||||
|
|
||||||
default_temp_allocator_proc :: nil_allocator_proc
|
default_temp_allocator_proc :: nil_allocator_proc
|
||||||
|
|
||||||
|
@(require_results)
|
||||||
|
default_temp_allocator_temp_begin :: proc(loc := #caller_location) -> (temp: Arena_Temp) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
default_temp_allocator_temp_end :: proc(temp: Arena_Temp, loc := #caller_location) {
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Default_Temp_Allocator :: struct {
|
Default_Temp_Allocator :: struct {
|
||||||
arena: Arena,
|
arena: Arena,
|
||||||
@@ -34,8 +42,27 @@ when ODIN_OS == .Freestanding || ODIN_OS == .JS || ODIN_DEFAULT_TO_NIL_ALLOCATOR
|
|||||||
s := (^Default_Temp_Allocator)(allocator_data)
|
s := (^Default_Temp_Allocator)(allocator_data)
|
||||||
return arena_allocator_proc(&s.arena, mode, size, alignment, old_memory, old_size, loc)
|
return arena_allocator_proc(&s.arena, mode, size, alignment, old_memory, old_size, loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(require_results)
|
||||||
|
default_temp_allocator_temp_begin :: proc(loc := #caller_location) -> (temp: Arena_Temp) {
|
||||||
|
if context.temp_allocator.data != &global_default_temp_allocator_data {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return arena_temp_begin(&global_default_temp_allocator_data.arena, loc)
|
||||||
|
}
|
||||||
|
|
||||||
|
default_temp_allocator_temp_end :: proc(temp: Arena_Temp, loc := #caller_location) {
|
||||||
|
arena_temp_end(temp, loc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@(deferred_out=default_temp_allocator_temp_end)
|
||||||
|
DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD :: #force_inline proc(loc := #caller_location) -> (Arena_Temp, Source_Code_Location) {
|
||||||
|
return default_temp_allocator_temp_begin(loc), loc
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
default_temp_allocator :: proc(allocator: ^Default_Temp_Allocator) -> Allocator {
|
default_temp_allocator :: proc(allocator: ^Default_Temp_Allocator) -> Allocator {
|
||||||
return Allocator{
|
return Allocator{
|
||||||
procedure = default_temp_allocator_proc,
|
procedure = default_temp_allocator_proc,
|
||||||
|
|||||||
Reference in New Issue
Block a user