diff options
| author | gingerBill <bill@gingerbill.org> | 2022-02-18 21:30:25 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-02-18 21:30:25 +0000 |
| commit | 71df46456a4db2592e8cebbdd4c46dc8b58b5a24 (patch) | |
| tree | 4152775ac24721cd026025d1e478d2eb9a254b41 /src/parser.cpp | |
| parent | cd89d8a3c414a6929ec058a04aeec568d99505a5 (diff) | |
Minimize memory usage by having an arena per thread rather than an arena per file
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 7309d9769..8a7ab2d20 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -57,6 +57,9 @@ isize ast_node_size(AstKind kind) { return align_formula_isize(gb_size_of(AstCommonStuff) + ast_variant_sizes[kind], gb_align_of(void *)); } + +gb_global std::atomic<isize> global_total_node_memory_allocated; + // NOTE(bill): And this below is why is I/we need a new language! Discriminated unions are a pain in C/C++ Ast *alloc_ast_node(AstFile *f, AstKind kind) { gbAllocator a = ast_allocator(f); @@ -66,6 +69,9 @@ Ast *alloc_ast_node(AstFile *f, AstKind kind) { Ast *node = cast(Ast *)gb_alloc(a, size); node->kind = kind; node->file_id = f ? f->id : 0; + + global_total_node_memory_allocated += size; + return node; } @@ -4851,12 +4857,6 @@ ParseFileError init_ast_file(AstFile *f, String fullpath, TokenPos *err_pos) { f->prev_token = f->tokens[f->prev_token_index]; f->curr_token = f->tokens[f->curr_token_index]; - isize const page_size = 4*1024; - isize block_size = 2*f->tokens.count*gb_size_of(Ast); - block_size = ((block_size + page_size-1)/page_size) * page_size; - block_size = gb_clamp(block_size, page_size, DEFAULT_MINIMUM_BLOCK_SIZE); - f->arena.minimum_block_size = block_size; - array_init(&f->comments, heap_allocator(), 0, 0); array_init(&f->imports, heap_allocator(), 0, 0); |