diff options
| author | Mistivia <i@mistivia.com> | 2025-06-09 17:58:16 +0800 |
|---|---|---|
| committer | Mistivia <i@mistivia.com> | 2025-06-09 17:58:16 +0800 |
| commit | d3fc3ae3c4663d3aa68b66002192a60287e8c6d0 (patch) | |
| tree | 79b239391559ce9e894981272d5a7fac03787a08 /src/arena.c | |
| parent | 2f0781104330d1ae4fae041560ee3a5cb892c3b6 (diff) | |
delete arena
Diffstat (limited to 'src/arena.c')
| -rw-r--r-- | src/arena.c | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/src/arena.c b/src/arena.c deleted file mode 100644 index f45d11b..0000000 --- a/src/arena.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "arena.h" - -#include <stdlib.h> - -void init_arena(arena_t *r, int blocksz) { - if (blocksz < 4096) blocksz = 4096; - r->head = (struct memblock){NULL, 0, blocksz}; - r->head.buf = malloc(blocksz); - r->current = &(r->head); - r->blocksz = blocksz; -} - -void destroy_arena(arena_t *r) { - free(r->head.buf); - struct memblock *cur = r->head.next; - while (cur != NULL) { - struct memblock *prev = cur; - cur = cur->next; - free(prev->buf); - free(prev); - } -} - -void *arena_alloc(arena_t *r, int sz) { - int remain = r->current->cap - r->current->sz; - if (remain >= sz) { - void *ptr = r->current->buf + r->current->sz; - r->current->sz += sz; - return ptr; - } - int blocksz = sz > blocksz ? sz : blocksz; - struct memblock *nextblock = malloc(sizeof(struct memblock)); - void *ptr = malloc(blocksz); - nextblock->buf = ptr; - nextblock->cap = blocksz; - nextblock->sz = sz; - r->current->next = nextblock; - r->current = nextblock; - return ptr; -} |
