1
0
Fork 0

Added: simple memory alignment mechanism

Browse Source
This commit is contained in:
rhuibertsjr 2024-04-26 17:23:37 +02:00
parent 304f9a1d0b
commit 4cc6fce555
3 changed files with 9 additions and 4 deletions

View File

@ -37,7 +37,8 @@ internal void *
arena_allocate(Arena *arena, u64 size)
{
Arena *current = arena->current;
u64 pos_mem = current->offset;
u64 pos_mem =
memory_align_power_of_two(current->offset, ARENA_DEFAULT_ALIGNMENT);
u64 pos_new = current->offset + size;
if (current->size < pos_new && current->growable)
@ -58,7 +59,8 @@ arena_allocate(Arena *arena, u64 size)
sll_stack_push(arena->current, new_memory_bock, prev);
current = new_memory_bock;
pos_mem = current->offset;
pos_mem =
memory_align_power_of_two(current->offset, ARENA_DEFAULT_ALIGNMENT);
pos_new = current->offset + size;
}

View File

@ -2,6 +2,7 @@
#define ARENA_H
#define ARENA_INITIAL_COMMIT_SIZE sizeof(struct Arena)
#define ARENA_DEFAULT_ALIGNMENT 8
#ifndef ARENA_DEFAULT_RESERVE_SIZE
# define ARENA_DEFAULT_RESERVE_SIZE KB(4)

View File

@ -39,6 +39,8 @@ typedef uint8_t b64;
//= rhjr: memory helpers
#define memory_align_power_of_two(x,b) (((x) + (b) - 1)&(~((b) - 1)))
#define memory_zero(s,z) memset((s), 0, (z))
#define memory_zero_struct(s) memory_zero((s), sizeof(*(s)))