Added: simple memory alignment mechanism
This commit is contained in:
parent
304f9a1d0b
commit
4cc6fce555
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user