diff options
| author | gingerBill <bill@gingerbill.org> | 2018-08-29 19:55:55 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-08-29 19:55:55 +0100 |
| commit | 001837e6bb0448d439ce6208069265a1a7aefaf5 (patch) | |
| tree | 7252984ec2c8d5844d8236006f9959b3dbee15da /core/runtime | |
| parent | 28523f17e2c702379dff89b024edcb1614256476 (diff) | |
Temporary allocator for `context`
Diffstat (limited to 'core/runtime')
| -rw-r--r-- | core/runtime/core.odin | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 7bf3a9826..9b3e96d56 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -184,7 +184,8 @@ Source_Code_Location :: struct { } Context :: struct { - allocator: mem.Allocator, + allocator: mem.Allocator, + temp_allocator: mem.Allocator, thread_id: int, user_data: any, @@ -194,6 +195,8 @@ Context :: struct { derived: any, // May be used for derived data types } +global_scratch_allocator_data: mem.Scratch_Allocator; + @@ -315,9 +318,15 @@ __init_context :: proc "contextless" (c: ^Context) { if c == nil do return; c.allocator = os.heap_allocator(); + c.temp_allocator = mem.scratch_allocator(&global_scratch_allocator_data); c.thread_id = os.current_thread_id(); } +@(builtin) +init_global_temporary_allocator :: proc(data: []byte, backup_allocator := context.allocator) { + mem.scratch_allocator_init(&global_scratch_allocator_data, data, backup_allocator); +} + @(builtin) |