feat: bounds check, refactor
This commit is contained in:
parent
c86df50063
commit
d6d4f2a0d9
1 changed files with 13 additions and 5 deletions
18
src/jalloc.c
18
src/jalloc.c
|
|
@ -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) {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue