diff options
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 485ba7cbd08..9c4113bb13a 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -21,7 +21,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): Geoffery Bantle * * ***** END GPL LICENSE BLOCK ***** */ @@ -31,9 +31,14 @@ */ #include "MEM_guardedalloc.h" + +#include "BKE_utildefines.h" + #include "BLI_blenlib.h" -#include "DNA_listBase.h" #include "BLI_linklist.h" + +#include "DNA_listBase.h" + #include <string.h> typedef struct BLI_freenode{ @@ -60,6 +65,9 @@ BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk) if (esize < sizeof(void*)) esize = sizeof(void*); + if (esize < sizeof(void*)) + esize = sizeof(void*); + /*allocate the pool structure*/ pool = MEM_mallocN(sizeof(BLI_mempool),"memory pool"); pool->esize = esize; @@ -68,7 +76,8 @@ BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk) pool->chunks.first = pool->chunks.last = NULL; maxchunks = tote / pchunk; - + if (maxchunks==0) maxchunks = 1; + /*allocate the actual chunks*/ for(i=0; i < maxchunks; i++){ BLI_mempool_chunk *mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk"); @@ -88,6 +97,7 @@ BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk) /*set the end of this chunks memoryy to the new tail for next iteration*/ lasttail = curnode; } + /*terminate the list*/ curnode->next = NULL; return pool; @@ -123,7 +133,7 @@ void *BLI_mempool_alloc(BLI_mempool *pool){ void *BLI_mempool_calloc(BLI_mempool *pool){ void *retval=NULL; retval = BLI_mempool_alloc(pool); - memset(retval, 0, pool->esize); + BMEMSET(retval, 0, pool->esize); return retval; } |