aboutsummaryrefslogtreecommitdiff
path: root/example.c
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2026-04-28 14:06:44 +0300
committerSyndamia <kamen@syndamia.com>2026-05-12 07:08:56 +0300
commit0d249b1d47a7f84cfe5f09ad070d1affd26566da (patch)
treef395f67eecb27daea3fc4a9ad8e59bf40f988984 /example.c
parent5c36b582ad60a569ed996fe188ed92ef6bd7fc5f (diff)
downloadfoollib-0d249b1d47a7f84cfe5f09ad070d1affd26566da.tar
foollib-0d249b1d47a7f84cfe5f09ad070d1affd26566da.tar.gz
foollib-0d249b1d47a7f84cfe5f09ad070d1affd26566da.zip
feat!: Refactor using MemoryManager
The idea is to provide a universal memory management "API", through which you allocate and deallocate. This allows our implementations (for String and Vector) to be more generic. It does also allow usage of different allocators depending on situation.
Diffstat (limited to 'example.c')
-rw-r--r--example.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/example.c b/example.c
index 00f79da..2f50152 100644
--- a/example.c
+++ b/example.c
@@ -1,38 +1,32 @@
-#include "Array.h"
-#include "BumpAlloc.h"
-#include "GlobalArena.h"
+#include "Vector.h"
#include "String.h"
+#include "BumpAlloc.h"
#include <stdio.h>
int
main() {
- g_arena = B_create(KiB(4));
- BumpArena t_arena = B_create(KiB(4));
+ MemoryManager g = M_bump(KiB(2)),
+ t = M_bump(KiB(3));
- String* hexes = AG_new(sizeof(String), 8);
- Result status = R_Ok;
+ String *hexes = V_new(&g, sizeof(String), 8);
+ Result status = R_Ok;
for (usize i = 7; i <= 4830; i += 69) {
- status = A_ppush(hexes, S_printf(t_arena, "%x", i));
-
- if (R_Ok != status) {
- fprintf(stderr, "Error(%d): %lu %lu\n", status, i, A_count(hexes));
- }
+ PRINT_NOTOK(V_pushp((void***)&hexes, S_printf(&t, "%x", i)));
}
- String all = SG_printf("Total: %ld\n", A_count(hexes));
- for (usize i = 0; i + 4 < A_count(hexes); i += 4) {
- Result status = S_append(all, S_concat(t_arena, hexes[0+i], " ", hexes[1+i], " ", hexes[2+i], " ", hexes[3+i], "\n", NULL));
-
- if (R_Ok != status) {
- fprintf(stderr, "Error(%d): %lu %lu\n", status, i, A_count(hexes));
- }
+ String all = S_printf(&g, "Total: %ld\n", V_count(hexes));
+ for (usize i = 0; i + 4 < V_count(hexes); i += 4) {
+ PRINT_NOTOK(
+ S_append(&all,
+ S_concat(&t,
+ hexes[0+i], " ", hexes[1+i], " ", hexes[2+i], " ", hexes[3+i], "\n",
+ NULL)));
}
printf("%s", all);
-
- B_destroy(g_arena);
- B_destroy(t_arena);
+ PRINT_NOTOK(g.destroy(&g));
+ PRINT_NOTOK(t.destroy(&t));
return 0;
}