aboutsummaryrefslogtreecommitdiff
path: root/src/bumpptr_alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bumpptr_alloc.c')
-rw-r--r--src/bumpptr_alloc.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/bumpptr_alloc.c b/src/bumpptr_alloc.c
index 2690809..576dc40 100644
--- a/src/bumpptr_alloc.c
+++ b/src/bumpptr_alloc.c
@@ -6,7 +6,11 @@
#include <string.h> /* memset */
#include <sys/mman.h> /* memset */
+#define MIN_ALIGNMENT 16
+
+#ifndef MEMSIZE
#define MEMSIZE 1024*4*1024*1024l
+#endif
#ifdef __cplusplus
extern "C" {
@@ -27,6 +31,12 @@ void* malloc(size_t size) {
ptr = (uintptr_t)mem_start;
}
+ // align ptr;
+ if (ptr % MIN_ALIGNMENT != 0) {
+ size_t mask = MIN_ALIGNMENT -1;
+ ptr = (ptr + mask) & ~mask;
+ }
+
void* ret = (void*)ptr;
ptr += size;
return ret;
@@ -49,8 +59,9 @@ void* realloc(void* ptr, size_t size) {
}
void* memalign(size_t alignment, size_t size) {
- // bump ptr to alignment and malloc
- ptr = (ptr + (alignment - 1)) & -alignment;
+ // align ptr to alignment and malloc
+ size_t mask = alignment - 1;
+ ptr = (ptr + mask) & ~mask;
return malloc(size);
}