diff options
Diffstat (limited to 'src/memory.c')
| -rw-r--r-- | src/memory.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/memory.c b/src/memory.c new file mode 100644 index 0000000..c2216b2 --- /dev/null +++ b/src/memory.c @@ -0,0 +1,43 @@ +#include <aplwc_internal.h> + +Memory +memory_init(uint8_t *data , size_t size) +{ + Memory mem = { + .data = data, + .size = size, + .offset = 0, + }; + return mem; +} + +static void * +alloc(Memory *m, size_t size, size_t align) +{ + uintptr_t ptr = (uintptr_t)m->data; + size_t alloc_size = size; + if((ptr % align) != 0) + alloc_size += align - (ptr % align); + + void *p = NULL; + if((m->size - m->offset) >= alloc_size){ + p = m->data+m->offset+alloc_size-size; + m->offset += alloc_size; + memset(p, 0, size); + } + return p; +} + +Aplwc * +memory_alloc_aplwc(Memory *m) +{ + Aplwc *p = alloc(m, sizeof(Aplwc), alignof(Aplwc)); + return p; +} + +void +memory_free_aplwc(Memory *m, Aplwc *p) +{ + UNUSED_PARAMETER(m); + UNUSED_PARAMETER(p); +} |