changeset 125:9b2b9bc2c362 malloc2

code cleaning
author Merten Sach <msach@mailbox.tu-berlin.de>
date Wed, 07 Sep 2011 14:28:20 +0200
parents e29bb31df078
children d0aa5a796fc5
files vmalloc.c vmalloc.h
diffstat 2 files changed, 7 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/vmalloc.c	Tue Aug 30 17:45:14 2011 +0200
     1.2 +++ b/vmalloc.c	Wed Sep 07 14:28:20 2011 +0200
     1.3 @@ -96,7 +96,7 @@
     1.4     
     1.5     //The last element in the list points to the container. If the container points
     1.6     //to NULL the container is empty
     1.7 -   if(*((void**)(chunk->prevChunkInFreeList)) == NULL && getChunkSize(chunk) >= 160);
     1.8 +   if(*((void**)(chunk->prevChunkInFreeList)) == NULL && getChunkSize(chunk) >= BIG_LOWER_BOUND);
     1.9     {
    1.10         //Find the approppiate container because we do not know it
    1.11         uint64 containerIdx = ((uintptr_t)chunk->prevChunkInFreeList - (uintptr_t)freeLists->bigChunks) >> 3;
    1.12 @@ -183,7 +183,7 @@
    1.13      size_t chunkSize     = getChunkSize(foundChunk);
    1.14  
    1.15      //If the new chunk is larger than the requested size: split
    1.16 -    if(chunkSize > sizeRequested + 2 * sizeof(MallocProlog) + 160)
    1.17 +    if(chunkSize > sizeRequested + 2 * sizeof(MallocProlog) + BIG_LOWER_BOUND)
    1.18      {
    1.19         MallocProlog *newChunk = divideChunk(foundChunk,sizeRequested);
    1.20         containerIdx = getContainer(getChunkSize(foundChunk)) - 1;
    1.21 @@ -290,11 +290,11 @@
    1.22     }
    1.23     
    1.24     size_t chunkSize = getChunkSize(chunkToFree);
    1.25 -   if(chunkSize < 160)
    1.26 +   if(chunkSize < BIG_LOWER_BOUND)
    1.27     {
    1.28         containerIdx =  (chunkSize/SMALL_CHUNK_SIZE)-1;
    1.29 -       if(containerIdx > 3)
    1.30 -           containerIdx = 3;
    1.31 +       if(containerIdx > SMALL_CHUNK_COUNT-1)
    1.32 +           containerIdx = SMALL_CHUNK_COUNT-1;
    1.33         insertChunk(chunkToFree, &freeLists->smallChunks[containerIdx]);
    1.34     }
    1.35     else
     2.1 --- a/vmalloc.h	Tue Aug 30 17:45:14 2011 +0200
     2.2 +++ b/vmalloc.h	Wed Sep 07 14:28:20 2011 +0200
     2.3 @@ -16,10 +16,8 @@
     2.4  
     2.5  #define SMALL_CHUNK_SIZE 32
     2.6  #define SMALL_CHUNK_COUNT 4
     2.7 -#define LOWER_BOUND 128
     2.8 -#define CHUNK_INCREASE_RATE 1.25
     2.9 -#define MAX_SMALL_CHUNKS 20
    2.10 -#define SMALL_CHUNKS_ALLOCATION 5
    2.11 +#define LOWER_BOUND     128  //Biggest chunk size that is created for the small chunks
    2.12 +#define BIG_LOWER_BOUND 160  //Smallest chunk size that is created for the big chunks
    2.13  
    2.14  #define LOG54 0.3219280948873623
    2.15  #define LOG128 7