Skip to content

Commit

Permalink
improve arena allocator behaviour
Browse files Browse the repository at this point in the history
previous commit also optimized the allocation of an arena struct
  • Loading branch information
ougi committed Mar 23, 2024
1 parent e438dda commit f89166f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ static inline void *ArenaPush(Arena *arena, size_t bytes) {

if (arena->pos + bytes > arena->size) {
/* need more memory! (make growable arena linked list) */
if (bytes > arena->size * ARENA_GROWTH_FACTOR) {
fprintf(
stderr, "FATAL: requested block won't fit in a single arena!"
" (Block: %zuB, Arena: %zuB)\n", bytes, arena->size
);
exit(-1);
}

if (!arena->next) {
size_t newSize = arena->size * ARENA_GROWTH_FACTOR;
if (bytes > newSize) {
fprintf(
stderr,
"FATAL: requested block won't fit in a single arena!"
" (Block: %zuB, Arena: %zuB)\n", bytes, arena->size
);
exit(EXIT_FAILURE);
}
#ifdef INSTRUMENTATION
printf(" ALLOCATING: new arena of %zuB...\n\n", newSize);
#endif
Expand Down

0 comments on commit f89166f

Please sign in to comment.