feat: bounds check, refactor

This commit is contained in:
jackjohn7 2026-06-15 22:35:03 -05:00
parent c86df50063
commit d6d4f2a0d9

View file

@ -2,13 +2,21 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#define HEAP_SIZE (1024 * 1024) #define HEAP_SIZE (1024 * 1024 * 2)
#define ALIGNMENT 8
static uint8_t heap[HEAP_SIZE]; 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]; * Allocate memory via bump allocation
heap_offset += size; */
void *jalloc(size_t size) {
if (heap_ptr + size > heap + sizeof(heap)) return NULL;
void *ptr = heap_ptr;
heap_ptr += size;
return ptr; return ptr;
} }
void jfree(void *ptr) {}