From: christoph Date: Wed, 28 Dec 2011 19:16:15 +0000 (+0100) Subject: added a slice allocator X-Git-Url: http://uxul.de/gitweb/?p=lazyeval.git;a=commitdiff_plain;h=551dec71ea4a993089a4b72ceb667a50ba3b6f92;ds=inline added a slice allocator --- 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; }