Temporary allocator for context

This commit is contained in:
gingerBill
2018-08-29 19:55:55 +01:00
parent 28523f17e2
commit 001837e6bb
7 changed files with 145 additions and 14 deletions
+10 -1
View File
@@ -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)