Mempool: remove BLI_MEMPOOL_SYSMALLOC, MEM_* allocs are more efficient now
authorCampbell Barton <ideasman42@gmail.com>
Fri, 4 Apr 2014 23:57:32 +0000 (10:57 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 5 Apr 2014 01:14:05 +0000 (12:14 +1100)
17 files changed:
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/pbvh_bmesh.c
source/blender/blenlib/BLI_linklist_stack.h
source/blender/blenlib/BLI_mempool.h
source/blender/blenlib/intern/BLI_ghash.c
source/blender/blenlib/intern/BLI_mempool.c
source/blender/blenlib/intern/edgehash.c
source/blender/bmesh/intern/bmesh_edgeloop.c
source/blender/bmesh/intern/bmesh_log.c
source/blender/bmesh/intern/bmesh_mesh.c
source/blender/bmesh/intern/bmesh_operators.c
source/blender/bmesh/intern/bmesh_walkers.c
source/blender/bmesh/operators/bmo_connect_pair.c
source/blender/bmesh/operators/bmo_hull.c
source/blender/bmesh/tools/bmesh_beautify.c
source/blender/bmesh/tools/bmesh_edgenet.c
source/blender/imbuf/intern/moviecache.c

index a628504268a57771ce90fd27db71d3191823bdf8..41eb2f5982efceb0cd42c9a22fc2f3d0561e5385 100644 (file)
@@ -2408,7 +2408,7 @@ void CustomData_bmesh_init_pool(CustomData *data, int totelem, const char htype)
 
        /* If there are no layers, no pool is needed just yet */
        if (data->totlayer) {
-               data->pool = BLI_mempool_create(data->totsize, totelem, chunksize, BLI_MEMPOOL_SYSMALLOC);
+               data->pool = BLI_mempool_create(data->totsize, totelem, chunksize, BLI_MEMPOOL_NOP);
        }
 }
 
index bb3561d38a62891b1987fb7de41622f7507e38c9..0bdd786f23e278799904bc33c7a37882061de386 100644 (file)
@@ -1189,8 +1189,7 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *bvh, PBVHTopologyUpdateMode mode,
 
        if (mode & PBVH_Collapse) {
                EdgeQueue q;
-               BLI_mempool *queue_pool = BLI_mempool_create(sizeof(BMVert *[2]),
-                                                            128, 128, 0);
+               BLI_mempool *queue_pool = BLI_mempool_create(sizeof(BMVert *[2]), 128, 128, BLI_MEMPOOL_NOP);
                EdgeQueueContext eq_ctx = {&q, queue_pool, bvh->bm, cd_vert_mask_offset};
 
                short_edge_queue_create(&eq_ctx, bvh, center, radius);
@@ -1203,8 +1202,7 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *bvh, PBVHTopologyUpdateMode mode,
 
        if (mode & PBVH_Subdivide) {
                EdgeQueue q;
-               BLI_mempool *queue_pool = BLI_mempool_create(sizeof(BMVert *[2]),
-                                                            128, 128, 0);
+               BLI_mempool *queue_pool = BLI_mempool_create(sizeof(BMVert *[2]), 128, 128, BLI_MEMPOOL_NOP);
                EdgeQueueContext eq_ctx = {&q, queue_pool, bvh->bm, cd_vert_mask_offset};
 
                long_edge_queue_create(&eq_ctx, bvh, center, radius);
index ef78fb9a305fd209fb37e5b2286390740e4e887b..c2aefc3f283704a5de3de5290da9127a61706c85 100644 (file)
@@ -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) \
index 3fab77f2cb2d0cf8589dab671325eb43121f123e..25694f4445b8124e794a6d073e0eeb3a0eeb77e0 100644 (file)
@@ -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();
index f3ebddddc8c115a0f2c09ea88e9f100cc990a223..169b98da267bb67f2aa19ce507db0b16b39964b1 100644 (file)
@@ -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;
 }
index 04a1b75fcda626d031be2d629a8f84514baf1780..e4cff4caae575b0269ed0ca3f3c1142e9773408e 100644 (file)
@@ -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
index c12efbd80f6a2e1ae58a71a93b736d495cccb573..c191d8b5b55627a09c8767163a55d0d4068603a6 100644 (file)
@@ -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;
 }
index 4c91f22759bee76fa05a1a4783611f9753af7d13..bedb9c56af6671f61270dba6e965011b49d065c5 100644 (file)
@@ -298,7 +298,7 @@ bool BM_mesh_edgeloops_find_path(BMesh *bm, ListBase *r_eloops,
                BMVert *v_match[2] = {NULL, NULL};
                ListBase lb_src = {NULL, NULL};
                ListBase lb_dst = {NULL, NULL};
-               BLI_mempool *vs_pool = BLI_mempool_create(sizeof(struct VertStep), 1, 512, 0);
+               BLI_mempool *vs_pool = BLI_mempool_create(sizeof(struct VertStep), 1, 512, BLI_MEMPOOL_NOP);
 
                /* edge args are dummy */
                vs_add(vs_pool, &lb_src, v_src, v_src->e,  1);
index dc8e85bc606747d7360adeef4c14bcf76f088ffe..372252db8fe7aaf006fbd344073bb3b8ee01fbcb 100644 (file)
@@ -373,8 +373,8 @@ static BMLogEntry *bm_log_entry_create(void)
        entry->added_faces = BLI_ghash_ptr_new(__func__);
        entry->modified_verts = BLI_ghash_ptr_new(__func__);
 
-       entry->pool_verts = BLI_mempool_create(sizeof(BMLogVert), 1, 64, 0);
-       entry->pool_faces = BLI_mempool_create(sizeof(BMLogFace), 1, 64, 0);
+       entry->pool_verts = BLI_mempool_create(sizeof(BMLogVert), 1, 64, BLI_MEMPOOL_NOP);
+       entry->pool_faces = BLI_mempool_create(sizeof(BMLogFace), 1, 64, BLI_MEMPOOL_NOP);
 
        return entry;
 }
index 66326a477432ca983ebf90ffed73ba2f8581d22f..ec01f13414eb0c2e6d888df142a8512a663230ee 100644 (file)
@@ -52,12 +52,12 @@ static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize)
        bm->epool = BLI_mempool_create(sizeof(BMEdge), allocsize->totedge,
                                       bm_mesh_chunksize_default.totedge, BLI_MEMPOOL_ALLOW_ITER);
        bm->lpool = BLI_mempool_create(sizeof(BMLoop), allocsize->totloop,
-                                      bm_mesh_chunksize_default.totloop, 0);
+                                      bm_mesh_chunksize_default.totloop, BLI_MEMPOOL_NOP);
        bm->fpool = BLI_mempool_create(sizeof(BMFace), allocsize->totface,
                                       bm_mesh_chunksize_default.totface, BLI_MEMPOOL_ALLOW_ITER);
 
 #ifdef USE_BMESH_HOLES
-       bm->looplistpool = BLI_mempool_create(sizeof(BMLoopList), 512, 512, 0);
+       bm->looplistpool = BLI_mempool_create(sizeof(BMLoopList), 512, 512, BLI_MEMPOOL_NOP);
 #endif
 }
 
@@ -67,9 +67,9 @@ void BM_mesh_elem_toolflags_ensure(BMesh *bm)
                return;
        }
 
-       bm->vtoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), max_ii(512, bm->totvert), 512, 0);
-       bm->etoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), max_ii(512, bm->totedge), 512, 0);
-       bm->ftoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), max_ii(512, bm->totface), 512, 0);
+       bm->vtoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), max_ii(512, bm->totvert), 512, BLI_MEMPOOL_NOP);
+       bm->etoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), max_ii(512, bm->totedge), 512, BLI_MEMPOOL_NOP);
+       bm->ftoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), max_ii(512, bm->totface), 512, BLI_MEMPOOL_NOP);
 
 #pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
        {
index 577e6144e9bb13749a4b2f18285ea84157a9e9dc..ec94602e8e23e13b47c0ac54cd9ff9afcad5c3ea 100644 (file)
@@ -1167,9 +1167,9 @@ static void bmo_flag_layer_alloc(BMesh *bm)
 
        bm->totflags++;
 
-       bm->vtoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, max_ii(512, bm->totvert), 512, 0);
-       bm->etoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, max_ii(512, bm->totedge), 512, 0);
-       bm->ftoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, max_ii(512, bm->totface), 512, 0);
+       bm->vtoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, max_ii(512, bm->totvert), 512, BLI_MEMPOOL_NOP);
+       bm->etoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, max_ii(512, bm->totedge), 512, BLI_MEMPOOL_NOP);
+       bm->ftoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, max_ii(512, bm->totface), 512, BLI_MEMPOOL_NOP);
 
 #pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
        {
@@ -1248,9 +1248,9 @@ static void bmo_flag_layer_free(BMesh *bm)
        /* de-increment the totflags first.. */
        bm->totflags--;
 
-       bm->vtoolflagpool = BLI_mempool_create(new_totflags_size, bm->totvert, 512, 0);
-       bm->etoolflagpool = BLI_mempool_create(new_totflags_size, bm->totedge, 512, 0);
-       bm->ftoolflagpool = BLI_mempool_create(new_totflags_size, bm->totface, 512, 0);
+       bm->vtoolflagpool = BLI_mempool_create(new_totflags_size, bm->totvert, 512, BLI_MEMPOOL_NOP);
+       bm->etoolflagpool = BLI_mempool_create(new_totflags_size, bm->totedge, 512, BLI_MEMPOOL_NOP);
+       bm->ftoolflagpool = BLI_mempool_create(new_totflags_size, bm->totface, 512, BLI_MEMPOOL_NOP);
 
 #pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
        {
index acb97d328cca7b9146fa284d1c07aa56e3d10dfa..72b4c5d6623f00fea14a7e0f4fa551f6f8950974 100644 (file)
@@ -115,7 +115,7 @@ void BMW_init(BMWalker *walker, BMesh *bm, int type,
                BLI_assert(mask_face == 0 || (walker->valid_mask & BM_FACE));
        }
        
-       walker->worklist = BLI_mempool_create(walker->structsize, 100, 100, BLI_MEMPOOL_SYSMALLOC);
+       walker->worklist = BLI_mempool_create(walker->structsize, 128, 128, BLI_MEMPOOL_NOP);
        BLI_listbase_clear(&walker->states);
 }
 
index b3d78f40b6fb9a5f67d9f7a1533cedbe8642b869..7f23744d61e4ac26aa2619d1690b3698b687fc83 100644 (file)
@@ -387,7 +387,7 @@ void bmo_connect_vert_pair_exec(BMesh *bm, BMOperator *op)
        /* setup context */
        {
                BLI_listbase_clear(&pc.state_lb);
-               pc.link_pool = BLI_mempool_create(sizeof(PathLink), 1, 512, BLI_MEMPOOL_SYSMALLOC);
+               pc.link_pool = BLI_mempool_create(sizeof(PathLink), 1, 512, BLI_MEMPOOL_NOP);
        }
 
        /* calculate matrix */
index 0a86a84d55b617e8205f5b66526046703f6c1ba8..c0aea34ec3569829affc8c4064e153262608be69 100644 (file)
@@ -213,8 +213,8 @@ static HullFinalEdges *hull_final_edges(GSet *hull_triangles)
        
        final_edges = MEM_callocN(sizeof(HullFinalEdges), "HullFinalEdges");
        final_edges->edges = BLI_ghash_ptr_new("final edges ghash");
-       final_edges->base_pool = BLI_mempool_create(sizeof(ListBase), 128, 128, 0);
-       final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 128, 128, 0);
+       final_edges->base_pool = BLI_mempool_create(sizeof(ListBase), 128, 128, BLI_MEMPOOL_NOP);
+       final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 128, 128, BLI_MEMPOOL_NOP);
 
        GSET_ITER (iter, hull_triangles) {
                LinkData *link;
@@ -574,7 +574,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op)
                        BMO_elem_flag_enable(bm, ele, HULL_FLAG_INTERIOR_ELE);
        }
 
-       hull_pool = BLI_mempool_create(sizeof(HullTriangle), 128, 128, 0);
+       hull_pool = BLI_mempool_create(sizeof(HullTriangle), 128, 128, BLI_MEMPOOL_NOP);
        hull_triangles = BLI_gset_ptr_new("hull_triangles");
 
        hull_from_bullet(bm, op, hull_triangles, hull_pool);
index 4b5c87892278e58c1fa6777fc62c933b6cf6d4f1..cbe704dbf191b6d1bd3f30fa71e19a554a41d260 100644 (file)
@@ -385,7 +385,7 @@ void BM_mesh_beautify_fill(BMesh *bm, BMEdge **edge_array, const int edge_array_
        HeapNode **eheap_table;  /* edge index aligned table pointing to the eheap */
 
        GSet       **edge_state_arr  = MEM_callocN((size_t)edge_array_len * sizeof(GSet *), __func__);
-       BLI_mempool *edge_state_pool = BLI_mempool_create(sizeof(EdRotState), 512, 512, BLI_MEMPOOL_SYSMALLOC);
+       BLI_mempool *edge_state_pool = BLI_mempool_create(sizeof(EdRotState), 512, 512, BLI_MEMPOOL_NOP);
        int i;
 
 #ifdef DEBUG_TIME
index 37a748c238ea45b3bf85d2999a4e138eb6ff3d46..576d604c1cb464b8dd9da236fb991f3cd9403939 100644 (file)
@@ -443,8 +443,8 @@ void BM_mesh_edgenet(BMesh *bm,
                      const bool use_edge_tag, const bool use_new_face_tag)
 {
        VertNetInfo *vnet_info = MEM_callocN(sizeof(*vnet_info) * (size_t)bm->totvert, __func__);
-       BLI_mempool *edge_queue_pool = BLI_mempool_create(sizeof(LinkNode), 1, 512, 0);
-       BLI_mempool *path_pool = BLI_mempool_create(sizeof(LinkNode), 1, 512, 0);
+       BLI_mempool *edge_queue_pool = BLI_mempool_create(sizeof(LinkNode), 1, 512, BLI_MEMPOOL_NOP);
+       BLI_mempool *path_pool = BLI_mempool_create(sizeof(LinkNode), 1, 512, BLI_MEMPOOL_NOP);
        LinkNode *edge_queue = NULL;
 
        BMEdge *e;
index 6b2251eb24a82452c3020c66ea2a83b481b91923..87043a5581a5a012967741459507b7a81cf447c4 100644 (file)
@@ -306,8 +306,8 @@ MovieCache *IMB_moviecache_create(const char *name, int keysize, GHashHashFP has
 
        BLI_strncpy(cache->name, name, sizeof(cache->name));
 
-       cache->keys_pool = BLI_mempool_create(sizeof(MovieCacheKey), 64, 64, 0);
-       cache->items_pool = BLI_mempool_create(sizeof(MovieCacheItem), 64, 64, 0);
+       cache->keys_pool = BLI_mempool_create(sizeof(MovieCacheKey), 64, 64, BLI_MEMPOOL_NOP);
+       cache->items_pool = BLI_mempool_create(sizeof(MovieCacheItem), 64, 64, BLI_MEMPOOL_NOP);
        cache->userkeys_pool = BLI_mempool_create(keysize, 64, 64, 0);
        cache->hash = BLI_ghash_new(moviecache_hashhash, moviecache_hashcmp, "MovieClip ImBuf cache hash");