2025-10-18 11:33:31 -05:00
|
|
|
#define DEBUG
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "../include/mem.h"
|
|
|
|
|
|
|
|
|
|
int main(void){
|
|
|
|
|
size_t nbytes = MEM_GB(1024);
|
|
|
|
|
Arena a;
|
|
|
|
|
TRY {
|
|
|
|
|
a = ARENA(0,nbytes); /* try 1GB */
|
|
|
|
|
if (!a.beg)
|
|
|
|
|
RAISE(OOM);
|
2025-10-18 11:39:47 -05:00
|
|
|
ARENA_FREE(a);
|
2025-10-18 11:33:31 -05:00
|
|
|
}
|
|
|
|
|
EXCEPT(OOM) {
|
|
|
|
|
/* handle memory failure gracefully */
|
|
|
|
|
fprintf(stderr, "Caught: %s\n", OOM.reason);
|
|
|
|
|
return EXIT_SUCCESS; /* requested behavior */
|
|
|
|
|
}
|
|
|
|
|
FINALLY {
|
|
|
|
|
/* cleanup if needed, runs always */
|
2025-10-18 11:39:47 -05:00
|
|
|
if (a.beg) ARENA_FREE(a);
|
2025-10-18 11:33:31 -05:00
|
|
|
}
|
|
|
|
|
END_TRY;
|
|
|
|
|
|
|
|
|
|
return EXIT_FAILURE; /* shouldn't reach here for this example */
|
|
|
|
|
}
|