diff --git a/src/jalloc.c b/src/jalloc.c index 7508b0e..4bd6120 100644 --- a/src/jalloc.c +++ b/src/jalloc.c @@ -2,13 +2,21 @@ #include #include -#define HEAP_SIZE (1024 * 1024) +#define HEAP_SIZE (1024 * 1024 * 2) +#define ALIGNMENT 8 static uint8_t heap[HEAP_SIZE]; -static size_t heap_offset = 0; +static uint8_t *heap_ptr = heap; -void* jalloc(size_t size) { - void* ptr = &heap[heap_offset]; - heap_offset += size; +/** + * Allocate memory via bump allocation + */ +void *jalloc(size_t size) { + if (heap_ptr + size > heap + sizeof(heap)) return NULL; + + void *ptr = heap_ptr; + heap_ptr += size; return ptr; } + +void jfree(void *ptr) {}