mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-12 06:11:26 -07:00
Minimize severe memory usage by enforcing the heap_allocator() in places
This commit is contained in:
+5
-10
@@ -60,7 +60,6 @@ gb_internal void virtual_memory_dealloc(MemoryBlock *block);
|
||||
gb_internal void *arena_alloc(Arena *arena, isize min_size, isize alignment);
|
||||
gb_internal void arena_free_all(Arena *arena);
|
||||
|
||||
|
||||
gb_internal isize arena_align_forward_offset(Arena *arena, isize alignment) {
|
||||
isize alignment_offset = 0;
|
||||
isize ptr = cast(isize)(arena->curr_block->base + arena->curr_block->used);
|
||||
@@ -75,7 +74,7 @@ gb_internal void *arena_alloc(Arena *arena, isize min_size, isize alignment) {
|
||||
GB_ASSERT(gb_is_power_of_two(alignment));
|
||||
|
||||
mutex_lock(&arena->mutex);
|
||||
|
||||
|
||||
isize size = 0;
|
||||
if (arena->curr_block != nullptr) {
|
||||
size = min_size + arena_align_forward_offset(arena, alignment);
|
||||
@@ -390,15 +389,11 @@ gb_internal bool IS_ODIN_DEBUG(void);
|
||||
gb_internal GB_ALLOCATOR_PROC(heap_allocator_proc);
|
||||
|
||||
|
||||
gb_global gb_thread_local Arena heap_arena = {nullptr, DEFAULT_MINIMUM_BLOCK_SIZE};
|
||||
gb_internal gbAllocator heap_allocator(void) {
|
||||
if (IS_ODIN_DEBUG()) {
|
||||
gbAllocator a;
|
||||
a.proc = heap_allocator_proc;
|
||||
a.data = nullptr;
|
||||
return a;
|
||||
}
|
||||
return arena_allocator(&heap_arena);
|
||||
gbAllocator a;
|
||||
a.proc = heap_allocator_proc;
|
||||
a.data = nullptr;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1192,15 +1192,16 @@ gb_internal lbProcedure *lb_create_cleanup_runtime(lbModule *main_module) { // C
|
||||
gb_internal WORKER_TASK_PROC(lb_generate_procedures_and_types_per_module) {
|
||||
lbModule *m = cast(lbModule *)data;
|
||||
for (Entity *e : m->global_procedures_and_types_to_create) {
|
||||
String mangled_name = lb_get_entity_name(m, e);
|
||||
|
||||
switch (e->kind) {
|
||||
case Entity_TypeName:
|
||||
if (e->kind == Entity_TypeName) {
|
||||
(void)lb_get_entity_name(m, e);
|
||||
lb_type(m, e->type);
|
||||
break;
|
||||
case Entity_Procedure:
|
||||
}
|
||||
}
|
||||
|
||||
for (Entity *e : m->global_procedures_and_types_to_create) {
|
||||
if (e->kind == Entity_Procedure) {
|
||||
(void)lb_get_entity_name(m, e);
|
||||
array_add(&m->procedures_to_generate, lb_create_procedure(m, e));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -121,18 +121,21 @@ gb_internal lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool i
|
||||
p->branch_blocks.allocator = a;
|
||||
p->context_stack.allocator = a;
|
||||
p->scope_stack.allocator = a;
|
||||
map_init(&p->selector_values, 0);
|
||||
map_init(&p->selector_addr, 0);
|
||||
map_init(&p->tuple_fix_map, 0);
|
||||
// map_init(&p->selector_values, 0);
|
||||
// map_init(&p->selector_addr, 0);
|
||||
// map_init(&p->tuple_fix_map, 0);
|
||||
|
||||
if (p->is_foreign) {
|
||||
lb_add_foreign_library_path(p->module, entity->Procedure.foreign_library);
|
||||
}
|
||||
|
||||
char *c_link_name = alloc_cstring(permanent_allocator(), p->name);
|
||||
LLVMTypeRef func_type = lb_get_procedure_raw_type(m, p->type);
|
||||
|
||||
p->value = LLVMAddFunction(m->mod, c_link_name, func_type);
|
||||
{
|
||||
TEMPORARY_ALLOCATOR_GUARD();
|
||||
char *c_link_name = alloc_cstring(temporary_allocator(), p->name);
|
||||
p->value = LLVMAddFunction(m->mod, c_link_name, func_type);
|
||||
}
|
||||
|
||||
lb_ensure_abi_function_type(m, p);
|
||||
lb_add_function_type_attributes(p->value, p->abi_function_type, p->abi_function_type->calling_convention);
|
||||
|
||||
+16
-9
@@ -27,6 +27,21 @@ gb_internal void thread_pool_wait(void) {
|
||||
}
|
||||
|
||||
|
||||
gb_internal i64 PRINT_PEAK_USAGE(void) {
|
||||
if (build_context.show_more_timings) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
PROCESS_MEMORY_COUNTERS p = {sizeof(p)};
|
||||
if (GetProcessMemoryInfo(GetCurrentProcess(), &p, sizeof(p))) {
|
||||
gb_printf("\n");
|
||||
gb_printf("Peak Memory Size: %.3f MiB\n", (cast(f64)p.PeakWorkingSetSize) / cast(f64)(1024ull * 1024ull));
|
||||
return cast(i64)p.PeakWorkingSetSize;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
gb_global BlockingMutex debugf_mutex;
|
||||
|
||||
gb_internal void debugf(char const *fmt, ...) {
|
||||
@@ -1731,15 +1746,7 @@ gb_internal void show_timings(Checker *c, Timings *t) {
|
||||
|
||||
timings_print_all(t);
|
||||
|
||||
if (build_context.show_more_timings) {
|
||||
#if defined(GB_SYSTEM_WINDOWS)
|
||||
PROCESS_MEMORY_COUNTERS p = {sizeof(p)};
|
||||
if (GetProcessMemoryInfo(GetCurrentProcess(), &p, sizeof(p))) {
|
||||
gb_printf("\n");
|
||||
gb_printf("Peak Memory Size: %.3f MiB\n", (cast(f64)p.PeakWorkingSetSize) / cast(f64)(1024ull * 1024ull));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
PRINT_PEAK_USAGE();
|
||||
|
||||
if (!(build_context.export_timings_format == TimingsExportUnspecified)) {
|
||||
timings_export_all(t, c, true);
|
||||
|
||||
Reference in New Issue
Block a user