|
1 | | -#ifndef CBM_ARENA_H |
2 | | -#define CBM_ARENA_H |
3 | | - |
4 | | -#include <stddef.h> |
5 | | - |
6 | | -// CBMArena is a simple bump allocator that allocates from fixed-size blocks. |
7 | | -// All memory is freed at once via cbm_arena_destroy(). Individual frees are not |
8 | | -// supported — this is by design for per-file extraction where all data has the |
9 | | -// same lifetime. |
10 | | -#define CBM_ARENA_MAX_BLOCKS 256 |
11 | | -#define CBM_ARENA_DEFAULT_BLOCK_SIZE (64 * 1024) // 64KB initial |
12 | | - |
13 | | -typedef struct { |
14 | | - char *blocks[CBM_ARENA_MAX_BLOCKS]; |
15 | | - size_t block_sizes[CBM_ARENA_MAX_BLOCKS]; // per-block sizes (for stats) |
16 | | - int nblocks; |
17 | | - size_t block_size; |
18 | | - size_t used; // bytes used in current block |
19 | | - size_t total_alloc; // cumulative bytes allocated (for stats) |
20 | | -} CBMArena; |
21 | | - |
22 | | -// Initialize an arena with the default block size. |
23 | | -void cbm_arena_init(CBMArena *a); |
24 | | - |
25 | | -// Allocate n bytes from the arena. Returns NULL on OOM or block exhaustion. |
26 | | -// All returned pointers are 8-byte aligned. |
27 | | -void *cbm_arena_alloc(CBMArena *a, size_t n); |
28 | | - |
29 | | -// Duplicate a string into arena memory. Returns arena-owned copy. |
30 | | -char *cbm_arena_strdup(CBMArena *a, const char *s); |
31 | | - |
32 | | -// Duplicate a string of known length into arena memory. NUL-terminates. |
33 | | -char *cbm_arena_strndup(CBMArena *a, const char *s, size_t len); |
34 | | - |
35 | | -// sprintf into arena memory. Returns arena-owned string. |
36 | | -char *cbm_arena_sprintf(CBMArena *a, const char *fmt, ...) __attribute__((format(printf, 2, 3))); |
37 | | - |
38 | | -// Free all blocks. Arena is invalid after this call. |
39 | | -void cbm_arena_destroy(CBMArena *a); |
40 | | - |
41 | | -#endif // CBM_ARENA_H |
| 1 | +/* The arena lives in src/foundation/arena.h. This file used to be a stale |
| 2 | + * copy with the same include guard and a shorter API; whichever header a |
| 3 | + * translation unit included first won, silently. One definition now. */ |
| 4 | +#ifndef CBM_INTERNAL_ARENA_SHIM_H |
| 5 | +#define CBM_INTERNAL_ARENA_SHIM_H |
| 6 | +#include "../../src/foundation/arena.h" /* relative: the lsp_all unit has no -Isrc */ |
| 7 | +#endif /* CBM_INTERNAL_ARENA_SHIM_H */ |
0 commit comments