Compare commits
No commits in common. "d608a8167477af5637662770078492df72eb63a8" and "de6aee3a3a9fc113d6bac4c8cd31b431fad02e8c" have entirely different histories.
d608a81674
...
de6aee3a3a
2 changed files with 15 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -Wall -O2
|
CFLAGS = -Wall -O2
|
||||||
|
|
||||||
CFLAGS += -DFREELIST_ALIGN
|
CFLAGS += -DFREELIST_NOALIGN
|
||||||
|
|
||||||
TARGET = main.elf
|
TARGET = main.elf
|
||||||
SRC = main.c freelist.c
|
SRC = main.c freelist.c
|
||||||
|
|
|
||||||
|
|
@ -5,24 +5,25 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* Align to nearest multiple of align */
|
/* Fiddle these around according to your need. Delete or check makefile */
|
||||||
static inline size_t align_up_to(size_t n, size_t align) {
|
#ifdef FREELIST_NOALIGN
|
||||||
return (n + align - 1) & ~(align - 1);
|
#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 */
|
#define ALIGN(x) (align_up(x))
|
||||||
#ifdef FREELIST_ALIGN
|
#endif // FREELIST_NOALIGN
|
||||||
#define ALIGN(x) (align_up_to(x, sizeof(void *)))
|
|
||||||
#else
|
|
||||||
#define ALIGN(x) (x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct FreeListBlock FreeListBlock;
|
typedef struct FreeListBlock FreeListBlock;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FreeListBlock *free;
|
|
||||||
uintptr_t start;
|
uintptr_t start;
|
||||||
uintptr_t end;
|
uintptr_t end;
|
||||||
|
FreeListBlock *free;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t allocated;
|
size_t allocated;
|
||||||
} FreeList;
|
} FreeList;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue