diff --git a/freelist/Makefile b/freelist/Makefile index f2e1377..9d85953 100644 --- a/freelist/Makefile +++ b/freelist/Makefile @@ -1,7 +1,7 @@ CC = gcc CFLAGS = -Wall -O2 -CFLAGS += -DFREELIST_ALIGN +CFLAGS += -DFREELIST_NOALIGN TARGET = main.elf SRC = main.c freelist.c diff --git a/freelist/freelist.h b/freelist/freelist.h index 015ee33..f0cf7c7 100644 --- a/freelist/freelist.h +++ b/freelist/freelist.h @@ -5,26 +5,27 @@ #include #include -/* Align to nearest multiple of align */ -static inline size_t align_up_to(size_t n, size_t align) { - return (n + align - 1) & ~(align - 1); +/* Fiddle these around according to your need. Delete or check makefile */ +#ifdef FREELIST_NOALIGN +#define ALIGN(x) (x) +#else // FREELIST_NOALIGN + +/* Align to nearest multiple of sizeof(void*) */ +static inline size_t align_up(size_t n) { + return (n + sizeof(void *) - 1) & ~(sizeof(void *) - 1); } -/* Fiddle these around according to your need. Delete or check makefile */ -#ifdef FREELIST_ALIGN -#define ALIGN(x) (align_up_to(x, sizeof(void *))) -#else -#define ALIGN(x) (x) -#endif +#define ALIGN(x) (align_up(x)) +#endif // FREELIST_NOALIGN typedef struct FreeListBlock FreeListBlock; typedef struct { + uintptr_t start; + uintptr_t end; FreeListBlock *free; - uintptr_t start; - uintptr_t end; - size_t size; - size_t allocated; + size_t size; + size_t allocated; } FreeList; int fl_init(FreeList *fl, uintptr_t start, uintptr_t end, size_t itemsize);