change align_forward to align_to

This commit is contained in:
Judah Caruso 2025-05-24 13:20:18 -06:00
parent 606bf14ffe
commit c72c27fc81
3 changed files with 5 additions and 9 deletions

View file

@ -92,7 +92,7 @@ arena_alloc :: (a: *Arena, count: int, alignment := Default_Align, loc := #calle
basic.assert(power_of_two(alignment)); basic.assert(power_of_two(alignment));
end := a.memory.(*u8) + a.offset; end := a.memory.(*u8) + a.offset;
ptr := align_forward(end.(int), alignment); ptr := align_to(end.(int), alignment);
total_size := (count + ptr.(*u8) - end.(*u8)).(u64); total_size := (count + ptr.(*u8) - end.(*u8)).(u64);
basic.assert(a.offset + total_size <= a.memory_size, "arena: out of memory", loc = loc); basic.assert(a.offset + total_size <= a.memory_size, "arena: out of memory", loc = loc);

View file

@ -34,7 +34,7 @@ power_of_two :: (x: int) -> bool {
return x & (x - 1) == 0; return x & (x - 1) == 0;
} }
align_forward :: (ptr: int, align: int = Default_Align) -> int { align_to :: (ptr: int, align: int = Default_Align) -> int {
basic.assert(power_of_two(align), "alignment must be a power of two"); basic.assert(power_of_two(align), "alignment must be a power of two");
p := ptr; p := ptr;
@ -74,7 +74,7 @@ allocator_restore :: (save_point: int) {
request_memory :: (size: int, align := Default_Align) -> *void { request_memory :: (size: int, align := Default_Align) -> *void {
allocator := context.allocator; allocator := context.allocator;
aligned_size := align_forward(size, align); aligned_size := align_to(size, align);
return allocator.proc(xx Extended_Allocator_Mode.request_memory, aligned_size.(int), 0, null, allocator.data); return allocator.proc(xx Extended_Allocator_Mode.request_memory, aligned_size.(int), 0, null, allocator.data);
} }

View file

@ -2,7 +2,7 @@ reload_main :: () {
system_allocator := context.allocator; system_allocator := context.allocator;
// Ensure we're not allocating anywhere unexpected // Ensure we're not allocating anywhere unexpected
context.allocator = mem.Crash_Allocator; context.allocator = mem.make_crash_allocator();
basic.set_working_directory(strings.path_strip_filename(system.get_path_of_running_executable())); basic.set_working_directory(strings.path_strip_filename(system.get_path_of_running_executable()));
@ -34,11 +34,7 @@ reload_main :: () {
lib_arena: mem.Arena; lib_arena: mem.Arena;
mem.init_arena(*lib_arena, lib_memory, H.max_memory); mem.init_arena(*lib_arena, lib_memory, H.max_memory);
lib_allocator := Allocator.{ lib_allocator := mem.make_arena_allocator(*lib_arena);
proc = mem.arena_allocator_proc,
data = *lib_arena,
};
lib_state := basic.alloc(xx H.state_size,, allocator = lib_allocator); lib_state := basic.alloc(xx H.state_size,, allocator = lib_allocator);
H.init(lib_state, lib_allocator, true); H.init(lib_state, lib_allocator, true);