Added arena free macro for cleanup and clarity

This commit is contained in:
2025-10-18 11:39:47 -05:00
parent 7f40dd92d6
commit 254958046a
4 changed files with 5 additions and 4 deletions

View File

@@ -44,5 +44,6 @@ extern void *mem_arena_alloc(int flags, Arena *a,
mem_arena_new((flags), (nbytes), __FILE__, __LINE__)
#define ARENA_ALLOC(flags, a, nbytes, align, count) \
mem_arena_alloc((flags), (a), (nbytes), (align), (count), __FILE__, __LINE__)
#define ARENA_FREE(a) mem_free(a.beg, __FILE__, __LINE__)
#endif

View File

@@ -7,6 +7,6 @@ int main(void){
Arena a = ARENA(0,nbytes);
ASSERTED(a.beg != NULL);
ASSERTED( mem_is_zero(a.beg, nbytes));
FREE(a.beg);
ARENA_FREE(a);
return EXIT_SUCCESS;
}

View File

@@ -7,6 +7,6 @@ int main(void){
Arena a = ARENA(NOZERO,nbytes);
ASSERTED(a.beg != NULL);
ASSERTED( !mem_is_zero(a.beg, nbytes));
FREE(a.beg);
ARENA_FREE(a);
return EXIT_SUCCESS;
}

View File

@@ -11,7 +11,7 @@ int main(void){
a = ARENA(0,nbytes); /* try 1GB */
if (!a.beg)
RAISE(OOM);
free(a.beg);
ARENA_FREE(a);
}
EXCEPT(OOM) {
/* handle memory failure gracefully */
@@ -20,7 +20,7 @@ int main(void){
}
FINALLY {
/* cleanup if needed, runs always */
if (a.beg) free(a.beg);
if (a.beg) ARENA_FREE(a);
}
END_TRY;