Modifying the class hierarchy and removing globals, allocators, simplifying

This commit is contained in:
Karol Krzosa (Nokia)
2022-12-31 20:10:11 +01:00
parent ffd6bc5d23
commit d75c54f61f
11 changed files with 153 additions and 168 deletions

View File

@@ -496,6 +496,18 @@ arena_push_size(Arena *a, size_t size){
return result;
}
CORE_Static Arena
push_arena(Allocator *allocator, size_t size, String debug_name) {
Arena result = {};
result.memory.data = (U8 *)allocate_size(allocator, size);
result.memory.reserve = size;
result.alignment = default_alignment;
result.debug_string = debug_name;
result.allocate = (Allocator::Allocate *)arena_push_size;
result.deallocate = (Allocator::Deallocate *)deallocate_stub;
return result;
}
CORE_Static void
arena_init(Arena *a, String debug_name){
a->memory = os_reserve(default_reserve_size);
@@ -634,7 +646,7 @@ struct Array{
*item = data[--len];
}
void init(Arena *a, S64 size = 16){
void init(Allocator *a, S64 size = 16){
allocator = a;
data = allocate_array(a, T, size);
cap = size;
@@ -686,7 +698,7 @@ struct Array{
template<class T>
CORE_Static Array<T>
array_make(Arena *a, S64 size = 16){
array_make(Allocator *a, S64 size = 16){
Array<T> result = {};
result.init(a, size);
return result;
@@ -774,7 +786,7 @@ map_grow(Map *map, S64 new_size){
}
CORE_Static Map
map_make(Arena *a, S64 size){
map_make(Allocator *a, S64 size){
Map result = {a};
map_grow(&result, size);
return result;
@@ -891,14 +903,14 @@ map_test(){
// String intern
//-----------------------------------------------------------------------------
struct Intern_Table{
Arena *string_allocator;
Allocator *string_allocator;
Map map;
U8 *first_keyword;
U8 *last_keyword;
};
CORE_Static Intern_Table
intern_table_make(Arena *string_allocator, Arena *map_allocator, S64 initial_size = 32){
intern_table_make(Allocator *string_allocator, Allocator *map_allocator, S64 initial_size = 32){
Intern_Table result = {};
result.map = map_make(map_allocator, initial_size);
result.string_allocator = string_allocator;
@@ -916,7 +928,7 @@ intern_string(Intern_Table *t, String string){
return result;
}
S64 *len_address = (S64 *)arena_push_size(t->string_allocator, string.len+1+sizeof(S64));
S64 *len_address = (S64 *)allocate_size(t->string_allocator, string.len+1+sizeof(S64), false);
*len_address = string.len;
U8 *string_address = (U8 *)(len_address + 1);