28 lines
681 B
C
28 lines
681 B
C
#ifndef ARENA_INCLUDED
|
|
#define ARENA_INCLUDED
|
|
|
|
#include <stddef.h>
|
|
|
|
#define SIZEOF(x) (ptrdiff_t)sizeof(x)
|
|
#define NELEMS(a) (sizeof(a) / sizeof(*(a)))
|
|
#define LEN(s) (NELEMS(s) - 1)
|
|
#define KB(x) ((size_t)(x) << 10) // 1 KB = 1024 bytes
|
|
#define MB(x) ((size_t)(x) << 20) // 1 MB = 1024 * 1024 bytes
|
|
#define GB(x) ((size_t)(x) << 30) // 1 GB = 1024 * 1024 * 1024 bytes
|
|
|
|
typedef struct {
|
|
char* beg;
|
|
char* end;
|
|
} Arena;
|
|
|
|
typedef enum {
|
|
NOZERO = 0x1,
|
|
SOFTFAIL = 0x2,
|
|
} ArenaFlags;
|
|
|
|
Arena arena_new(ptrdiff_t cap, int flags);
|
|
char* arena_alloc(Arena* a, ptrdiff_t nb, ptrdiff_t align, ptrdiff_t count, int flags);
|
|
|
|
|
|
#endif
|