Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-04-05 03:57:32 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-04-05 05:14:05 +0400
commitaf59ee340f8859bdcd5f09c54bcb48776adf0c0a (patch)
tree710718e1336b37d007adfd24f5aaec9b83277fbb /source/blender/blenlib
parent321c35ec6ccc91057329af9e5a139715ddc38486 (diff)
Mempool: remove BLI_MEMPOOL_SYSMALLOC, MEM_* allocs are more efficient now
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_linklist_stack.h2
-rw-r--r--source/blender/blenlib/BLI_mempool.h4
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c2
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c56
-rw-r--r--source/blender/blenlib/intern/edgehash.c2
5 files changed, 19 insertions, 47 deletions
diff --git a/source/blender/blenlib/BLI_linklist_stack.h b/source/blender/blenlib/BLI_linklist_stack.h
index ef78fb9a305..c2aefc3f283 100644
--- a/source/blender/blenlib/BLI_linklist_stack.h
+++ b/source/blender/blenlib/BLI_linklist_stack.h
@@ -56,7 +56,7 @@
#define BLI_LINKSTACK_INIT(var) { \
var = NULL; \
- _##var##_pool = BLI_mempool_create(sizeof(LinkNode), 1, 64, 0); \
+ _##var##_pool = BLI_mempool_create(sizeof(LinkNode), 1, 64, BLI_MEMPOOL_NOP); \
} (void)0
#define BLI_LINKSTACK_SIZE(var) \
diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h
index 3fab77f2cb2..25694f4445b 100644
--- a/source/blender/blenlib/BLI_mempool.h
+++ b/source/blender/blenlib/BLI_mempool.h
@@ -81,8 +81,8 @@ typedef struct BLI_mempool_iter {
/* flag */
enum {
- BLI_MEMPOOL_SYSMALLOC = (1 << 0),
- BLI_MEMPOOL_ALLOW_ITER = (1 << 1)
+ BLI_MEMPOOL_NOP = 0,
+ BLI_MEMPOOL_ALLOW_ITER = (1 << 0),
};
void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) ATTR_NONNULL();
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index f3ebddddc8c..169b98da267 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -191,7 +191,7 @@ static GHash *ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info,
}
gh->buckets = MEM_callocN(gh->nbuckets * sizeof(*gh->buckets), "buckets");
- gh->entrypool = BLI_mempool_create(entry_size, 64, 64, 0);
+ gh->entrypool = BLI_mempool_create(entry_size, 64, 64, BLI_MEMPOOL_NOP);
return gh;
}
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index 04a1b75fcda..e4cff4caae5 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -140,21 +140,10 @@ static BLI_mempool_chunk *mempool_chunk_alloc(BLI_mempool *pool)
{
BLI_mempool_chunk *mpchunk;
#ifdef USE_DATA_PTR
- if (pool->flag & BLI_MEMPOOL_SYSMALLOC) {
- mpchunk = malloc(sizeof(BLI_mempool_chunk));
- CHUNK_DATA(mpchunk) = malloc((size_t)pool->csize);
- }
- else {
- mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk");
- CHUNK_DATA(mpchunk) = MEM_mallocN((size_t)pool->csize, "BLI Mempool Chunk Data");
- }
+ mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk");
+ CHUNK_DATA(mpchunk) = MEM_mallocN((size_t)pool->csize, "BLI Mempool Chunk Data");
#else
- if (pool->flag & BLI_MEMPOOL_SYSMALLOC) {
- mpchunk = malloc(sizeof(BLI_mempool_chunk) + (size_t)pool->csize);
- }
- else {
- mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk) + (size_t)pool->csize, "BLI_Mempool Chunk");
- }
+ mpchunk = MEM_mallocN(sizeof(BLI_mempool_chunk) + (size_t)pool->csize, "BLI_Mempool Chunk");
#endif
return mpchunk;
@@ -219,29 +208,22 @@ static BLI_freenode *mempool_chunk_add(BLI_mempool *pool, BLI_mempool_chunk *mpc
return curnode;
}
-static void mempool_chunk_free(BLI_mempool_chunk *mpchunk, const unsigned int flag)
+static void mempool_chunk_free(BLI_mempool_chunk *mpchunk)
{
- if (flag & BLI_MEMPOOL_SYSMALLOC) {
-#ifdef USE_DATA_PTR
- free(CHUNK_DATA(mpchunk));
-#endif
- free(mpchunk);
- }
- else {
+
#ifdef USE_DATA_PTR
- MEM_freeN(CHUNK_DATA(mpchunk));
+ MEM_freeN(CHUNK_DATA(mpchunk));
#endif
- MEM_freeN(mpchunk);
- }
+ MEM_freeN(mpchunk);
}
-static void mempool_chunk_free_all(BLI_mempool_chunk *mpchunk, const unsigned int flag)
+static void mempool_chunk_free_all(BLI_mempool_chunk *mpchunk)
{
BLI_mempool_chunk *mpchunk_next;
for (; mpchunk; mpchunk = mpchunk_next) {
mpchunk_next = mpchunk->next;
- mempool_chunk_free(mpchunk, flag);
+ mempool_chunk_free(mpchunk);
}
}
@@ -253,12 +235,7 @@ BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem,
unsigned int i, maxchunks;
/* allocate the pool structure */
- if (flag & BLI_MEMPOOL_SYSMALLOC) {
- pool = malloc(sizeof(BLI_mempool));
- }
- else {
- pool = MEM_mallocN(sizeof(BLI_mempool), "memory pool");
- }
+ pool = MEM_mallocN(sizeof(BLI_mempool), "memory pool");
/* set the elem size */
if (esize < (int)MEMPOOL_ELEM_SIZE_MIN) {
@@ -387,7 +364,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr)
BLI_mempool_chunk *first;
first = pool->chunks;
- mempool_chunk_free_all(first->next, pool->flag);
+ mempool_chunk_free_all(first->next);
first->next = NULL;
#ifdef USE_TOTALLOC
@@ -602,7 +579,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve)
do {
mpchunk_next = mpchunk->next;
- mempool_chunk_free(mpchunk, pool->flag);
+ mempool_chunk_free(mpchunk);
} while ((mpchunk = mpchunk_next));
}
@@ -635,18 +612,13 @@ void BLI_mempool_clear(BLI_mempool *pool)
*/
void BLI_mempool_destroy(BLI_mempool *pool)
{
- mempool_chunk_free_all(pool->chunks, pool->flag);
+ mempool_chunk_free_all(pool->chunks);
#ifdef WITH_MEM_VALGRIND
VALGRIND_DESTROY_MEMPOOL(pool);
#endif
- if (pool->flag & BLI_MEMPOOL_SYSMALLOC) {
- free(pool);
- }
- else {
- MEM_freeN(pool);
- }
+ MEM_freeN(pool);
}
#ifndef NDEBUG
diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c
index c12efbd80f6..c191d8b5b55 100644
--- a/source/blender/blenlib/intern/edgehash.c
+++ b/source/blender/blenlib/intern/edgehash.c
@@ -190,7 +190,7 @@ static EdgeHash *edgehash_new(const char *info,
}
eh->buckets = MEM_callocN(eh->nbuckets * sizeof(*eh->buckets), "eh buckets");
- eh->epool = BLI_mempool_create(entry_size, 512, 512, BLI_MEMPOOL_SYSMALLOC);
+ eh->epool = BLI_mempool_create(entry_size, 512, 512, BLI_MEMPOOL_NOP);
return eh;
}