Add mem.Allocator_Mode.Query_Features, mem.Allocator_Mode_Set, mem.query_features`

This commit is contained in:
gingerBill
2020-08-16 22:07:40 +01:00
parent 1f571f48e5
commit 033b46def8
5 changed files with 92 additions and 1 deletions
+18
View File
@@ -10,9 +10,15 @@ Allocator_Mode :: enum byte {
Free,
Free_All,
Resize,
Query_Features,
}
*/
Allocator_Mode_Set :: runtime.Allocator_Mode_Set;
/*
Allocator_Mode_Set :: distinct bit_set[Allocator_Mode];
*/
Allocator_Proc :: runtime.Allocator_Proc;
/*
Allocator_Proc :: #type proc(allocator_data: rawptr, mode: Allocator_Mode,
@@ -63,6 +69,18 @@ resize :: inline proc(ptr: rawptr, old_size, new_size: int, alignment: int = DEF
return allocator.procedure(allocator.data, Allocator_Mode.Resize, new_size, alignment, ptr, old_size, 0, loc);
}
query_features :: proc(allocator: Allocator, loc := #caller_location) -> Allocator_Mode_Set {
if allocator.procedure != nil {
set: Allocator_Mode_Set;
res := allocator.procedure(allocator.data, Allocator_Mode.Query_Features, 0, 0, &set, 0, 0, loc);
if res == &set {
return set;
}
}
return nil;
}
delete_string :: proc(str: string, allocator := context.allocator, loc := #caller_location) {
free(raw_data(str), allocator, loc);