feat and refactor: Added mult_size_t_safe and changed how new capacity is calculated for an arena
I wanted to separate things but i was getting confused on how exactly to do it so i did the best i could, just multiply everithing by 2 and if it overflows then well, return error, should be enough for most cases to be honest
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
typedef struct {
|
||||
uint8_t *buffer;
|
||||
size_t size;
|
||||
size_t capacity;
|
||||
size_t offset;
|
||||
} Arena;
|
||||
|
||||
@@ -19,6 +19,7 @@ typedef enum {
|
||||
ARENA_NULL_ARG,
|
||||
ARENA_INVALID_SIZE,
|
||||
ARENA_INVALID_ALIGN,
|
||||
ARENA_CAPACITY_OVERFLOW,
|
||||
} ArenaErr;
|
||||
|
||||
typedef struct {
|
||||
@@ -45,14 +46,17 @@ typedef struct {
|
||||
};
|
||||
} SizeResult;
|
||||
|
||||
ArenaResult arena_init(size_t size);
|
||||
ArenaResult arena_init(size_t capacity);
|
||||
void arena_destroy(Arena *arena);
|
||||
|
||||
ArenaPointer arena_alloc(Arena *arena, size_t size, size_t alignment);
|
||||
ArenaErr arena_push(Arena *arena, void *data, size_t size, size_t alignment);
|
||||
ArenaErr arena_realloc(Arena *arena, size_t new_size);
|
||||
ArenaErr arena_realloc(Arena *arena, size_t new_capacity);
|
||||
|
||||
SizeResult align_arena_offset(Arena *arena, size_t alignment);
|
||||
SizeResult arena_compute_necessary_capacity(size_t capacity, size_t elem_size);
|
||||
|
||||
// Should be moved to something like general utilities,
|
||||
// i should make one for all my c projects
|
||||
bool mul_size_t_safe(size_t a, size_t b, size_t *out);
|
||||
|
||||
#endif // !ARENA_H
|
||||
|
||||
Reference in New Issue
Block a user