scratch memory improvements

This commit is contained in:
PS 2022-04-12 08:01:17 +02:00
parent 09db50e3d4
commit f6ab76ee2a
4 changed files with 7 additions and 7 deletions

View File

@ -7,7 +7,7 @@ lumenarium_init()
App_State* state = 0; App_State* state = 0;
permanent = bump_allocator_create_reserve(GB(2)); permanent = bump_allocator_create_reserve(GB(2));
scratch_ = bump_allocator_create_reserve(GB(8)); global_scratch_ = bump_allocator_create_reserve(GB(8));
platform_file_jobs_init(); platform_file_jobs_init();
run_tests(); run_tests();
@ -40,7 +40,7 @@ lumenarium_init()
internal void internal void
lumenarium_frame_prepare(App_State* state) lumenarium_frame_prepare(App_State* state)
{ {
allocator_clear(scratch_); allocator_clear(global_scratch_);
input_state_swap_frames(state->input_state); input_state_swap_frames(state->input_state);

View File

@ -14,10 +14,8 @@ typedef struct App_State App_State;
#include "lumenarium_hash.cpp" #include "lumenarium_hash.cpp"
#include "lumenarium_geometry.h" #include "lumenarium_geometry.h"
global Allocator* scratch_; // gets reset at frame boundaries global Allocator* global_scratch_; // gets reset at frame boundaries
#define scratch_get(ident) Allocator_Scratch ident = Allocator_Scratch(global_scratch_)
#define scratch_get(ident) Allocator_Scratch ident = Allocator_Scratch(scratch_)
#include "lumenarium_bsp.h" #include "lumenarium_bsp.h"
// Engine // Engine

View File

@ -94,6 +94,7 @@ struct Allocator_Bump
u64 size_committed; u64 size_committed;
u64 size_reserved; u64 size_reserved;
u64 page_size; u64 page_size;
u64 high_water_mark;
}; };
internal u8* internal u8*
@ -152,7 +153,7 @@ bump_allocator_alloc_inner(Allocator* allocator, Allocator_Bump* bump, u64 size)
u8* result = bump->base + bump->at; u8* result = bump->base + bump->at;
bump->at = at_after; bump->at = at_after;
bump->high_water_mark = max(bump->at, bump->high_water_mark);
return result; return result;
} }
@ -248,6 +249,7 @@ bump_allocator_create_child(Allocator* parent, u64 init_size)
result->parent = parent; result->parent = parent;
Allocator_Bump* bump = (Allocator_Bump*)result->allocator_data; Allocator_Bump* bump = (Allocator_Bump*)result->allocator_data;
zero_struct(*bump);
bump->base = allocator_alloc(result->parent, init_size); bump->base = allocator_alloc(result->parent, init_size);
if (bump->base != 0) if (bump->base != 0)
{ {