#include "aplwc_internal.h" struct memory memory_init(uint8_t *data , size_t size) { struct memory mem; mem.data = data; mem.size = size; mem.offset = 0; return mem; } static void * alloc(struct memory *m, size_t size, size_t align) { uintptr_t ptr; size_t alloc_size, adjust; void *p; ptr = (uintptr_t)m->data; alloc_size = size; if(NEVER(align == 0)) return NULL; adjust = ptr % align; if(adjust) alloc_size += align - adjust; if((m->size - m->offset) >= alloc_size){ p = m->data+m->offset+alloc_size-size; m->offset += alloc_size; memset(p, 0, size); }else p = NULL; return p; } struct aplwc * memory_alloc_aplwc(struct memory *m) { struct aplwc *p; p = alloc(m, sizeof(struct aplwc), alignof(struct aplwc)); return p; } void memory_free_aplwc(struct memory *m, struct aplwc *p) { UNUSED_PARAMETER(m); UNUSED_PARAMETER(p); }