Added temp arena and todos for growable arena flag.

This commit is contained in:
2025-02-08 10:28:12 +02:00
parent a4d8079661
commit f4dfb64b7a
+28
View File
@@ -42,6 +42,15 @@ struct Arena {
usize data_len; usize data_len;
usize prev_offset; usize prev_offset;
usize curr_offset; usize curr_offset;
// TODO
// u8 growable;
};
typedef struct Temp_Arena_Memory Temp_Arena_Memory;
struct Temp_Arena_Memory {
Arena *arena;
size_t prev_offset;
size_t curr_offset;
}; };
u8 is_power_of_two(uptr x); u8 is_power_of_two(uptr x);
@@ -53,6 +62,7 @@ void *arena_alloc(Arena *a, usize size);
void *arena_resize_align(Arena *a, void *old_memory, usize old_size, usize new_size, usize align); void *arena_resize_align(Arena *a, void *old_memory, usize old_size, usize new_size, usize align);
void *arena_resize(Arena *a, void *old_memory, usize old_size, usize new_size); void *arena_resize(Arena *a, void *old_memory, usize old_size, usize new_size);
// TODO
// arena_grow(); // arena_grow();
// Free the allocated arena // Free the allocated arena
@@ -67,6 +77,11 @@ void arena_reset(Arena *arena);
// REQUIRED to arena.data after used // REQUIRED to arena.data after used
Arena arena_new(usize arena_init_size); Arena arena_new(usize arena_init_size);
// Temp arena using the passed arena instance
Temp_Arena_Memory temp_arena_memory_begin(Arena *a);
// Clear the temp arena
void temp_arena_memory_end(Temp_Arena_Memory temp);
// -------------------------------------- // --------------------------------------
// -------------------------------------- // --------------------------------------
// implementation Below // implementation Below
@@ -173,6 +188,19 @@ void arena_free(Arena* arena) {
} }
} }
Temp_Arena_Memory temp_arena_memory_begin(Arena *a) {
Temp_Arena_Memory temp;
temp.arena = a;
temp.prev_offset = a->prev_offset;
temp.curr_offset = a->curr_offset;
return temp;
}
void temp_arena_memory_end(Temp_Arena_Memory temp) {
temp.arena->prev_offset = temp.prev_offset;
temp.arena->curr_offset = temp.curr_offset;
}
Arena arena_new(usize arena_init_size) { Arena arena_new(usize arena_init_size) {
Arena arena = {0}; Arena arena = {0};