From 551dec71ea4a993089a4b72ceb667a50ba3b6f92 Mon Sep 17 00:00:00 2001 From: christoph Date: Wed, 28 Dec 2011 20:16:15 +0100 Subject: [PATCH] added a slice allocator --- withMulklib.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/withMulklib.c b/withMulklib.c index cf4bf4f..f8c4b34 100644 --- a/withMulklib.c +++ b/withMulklib.c @@ -12,6 +12,22 @@ /* This code is only for x86_64 gcc linux. It is NOT threadsafe. */ +void* slice_alloc (size_t length) { + static intptr_t *nextslice = NULL + 1; + static intptr_t *lastslice = NULL; + + int num = length / sizeof(intptr_t) + 1; + + if (lastslice < nextslice + num) { + nextslice = (intptr_t *)malloc(1024*sizeof(intptr_t)); + lastslice = nextslice + 1023; + } + + void* ret = (void*) nextslice; + nextslice += num; + return ret; +} + /* w00t, I am a three-star-programmer! */ void ***dereferencedPointer; void ***lastDereferencedPointer; @@ -78,8 +94,7 @@ void*** lazy_alloc (void* (*calculate) (void*), void* opt) { lockedPointer++; dereferencedPointer++; - /* we should use a slice allocator here */ - tree_entry *en = (tree_entry*) malloc (sizeof(tree_entry)); + tree_entry *en = (tree_entry*) slice_alloc (sizeof(tree_entry)); en->function = calculate; en->argument = opt; en->dereferencedPointer = ret; @@ -219,7 +234,7 @@ inline void initializeSignalHandler () { } void *calculateLazy24 (void* bla) { - int* ret = (int*) malloc(sizeof(int)); + int* ret = (int*) slice_alloc (sizeof(int)); *ret = 42; return (void*) ret; } -- 2.20.1