Mempool: delay allocating an initial chunk, its not always used
authorCampbell Barton <ideasman42@gmail.com>
Tue, 8 Apr 2014 01:59:28 +0000 (11:59 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 8 Apr 2014 02:58:56 +0000 (12:58 +1000)
15 files changed:
source/blender/blenkernel/intern/pbvh_bmesh.c
source/blender/blenlib/BLI_linklist_stack.h
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/editors/mesh/editmesh_knife.c
source/blender/imbuf/intern/moviecache.c

index ae2f9b2824bb719f4d3a51d335f328cd5d64792d..bba949fcadf79a8717adccd6c9a55f5d68043d56 100644 (file)
@@ -1191,7 +1191,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, BLI_MEMPOOL_NOP);
+               BLI_mempool *queue_pool = BLI_mempool_create(sizeof(BMVert *[2]), 0, 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);
@@ -1204,7 +1204,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, BLI_MEMPOOL_NOP);
+               BLI_mempool *queue_pool = BLI_mempool_create(sizeof(BMVert *[2]), 0, 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 c2aefc3f283704a5de3de5290da9127a61706c85..ce82ab491c3c624106d07fa5f8b62c7fef8f0247 100644 (file)
@@ -56,7 +56,7 @@
 
 #define BLI_LINKSTACK_INIT(var)  { \
        var = NULL; \
-       _##var##_pool = BLI_mempool_create(sizeof(LinkNode), 1, 64, BLI_MEMPOOL_NOP); \
+       _##var##_pool = BLI_mempool_create(sizeof(LinkNode), 0, 64, BLI_MEMPOOL_NOP); \
 } (void)0
 
 #define BLI_LINKSTACK_SIZE(var) \
index c89178971854001a349d66fa72a594332148d868..3c158faaa1beb15154351acf2766daea9523ca3f 100644 (file)
@@ -311,10 +311,12 @@ BLI_mempool *BLI_mempool_create(unsigned int esize, unsigned int totelem,
 #endif
        pool->totused = 0;
 
-       /* allocate the actual chunks */
-       for (i = 0; i < maxchunks; i++) {
-               BLI_mempool_chunk *mpchunk = mempool_chunk_alloc(pool);
-               lasttail = mempool_chunk_add(pool, mpchunk, lasttail);
+       if (totelem) {
+               /* allocate the actual chunks */
+               for (i = 0; i < maxchunks; i++) {
+                       BLI_mempool_chunk *mpchunk = mempool_chunk_alloc(pool);
+                       lasttail = mempool_chunk_add(pool, mpchunk, lasttail);
+               }
        }
 
 #ifdef WITH_MEM_VALGRIND
index c191d8b5b55627a09c8767163a55d0d4068603a6..1d0e62dfdf6a3d4c7102861259731126b635885e 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_NOP);
+       eh->epool = BLI_mempool_create(entry_size, nentries_reserve, 512, BLI_MEMPOOL_NOP);
 
        return eh;
 }
index bedb9c56af6671f61270dba6e965011b49d065c5..08c405f956929a5267ce574869ff85262c74bf6a 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, BLI_MEMPOOL_NOP);
+               BLI_mempool *vs_pool = BLI_mempool_create(sizeof(struct VertStep), 0, 512, BLI_MEMPOOL_NOP);
 
                /* edge args are dummy */
                vs_add(vs_pool, &lb_src, v_src, v_src->e,  1);
index 5f0c11d1d069b451ed93f657ec61738085eaf4e0..f7c2b7d7fe6afebb01750f6f43248a21c9292b35 100644 (file)
@@ -375,8 +375,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, BLI_MEMPOOL_NOP);
-       entry->pool_faces = BLI_mempool_create(sizeof(BMLogFace), 1, 64, BLI_MEMPOOL_NOP);
+       entry->pool_verts = BLI_mempool_create(sizeof(BMLogVert), 0, 64, BLI_MEMPOOL_NOP);
+       entry->pool_faces = BLI_mempool_create(sizeof(BMLogFace), 0, 64, BLI_MEMPOOL_NOP);
 
        return entry;
 }
index ec01f13414eb0c2e6d888df142a8512a663230ee..23572d3ba16379e4cce70e18f5418a1bc01889c8 100644 (file)
@@ -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, 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);
+       bm->vtoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), bm->totvert, 512, BLI_MEMPOOL_NOP);
+       bm->etoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), bm->totedge, 512, BLI_MEMPOOL_NOP);
+       bm->ftoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer), bm->totface, 512, BLI_MEMPOOL_NOP);
 
 #pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
        {
index ec94602e8e23e13b47c0ac54cd9ff9afcad5c3ea..086233ebe09eb170d919539be242eef1a49e113f 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, 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);
+       bm->vtoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, bm->totvert, 512, BLI_MEMPOOL_NOP);
+       bm->etoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, bm->totedge, 512, BLI_MEMPOOL_NOP);
+       bm->ftoolflagpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, bm->totface, 512, BLI_MEMPOOL_NOP);
 
 #pragma omp parallel sections if (bm->totvert + bm->totedge + bm->totface >= BM_OMP_LIMIT)
        {
index 72b4c5d6623f00fea14a7e0f4fa551f6f8950974..75513a48d98ba50534cd70c2cc31f749933a3fb4 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, 128, 128, BLI_MEMPOOL_NOP);
+       walker->worklist = BLI_mempool_create(walker->structsize, 0, 128, BLI_MEMPOOL_NOP);
        BLI_listbase_clear(&walker->states);
 }
 
index 7f23744d61e4ac26aa2619d1690b3698b687fc83..b497ab2f693794afbc49daebbf7d94c358e1a42a 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_NOP);
+               pc.link_pool = BLI_mempool_create(sizeof(PathLink), 0, 512, BLI_MEMPOOL_NOP);
        }
 
        /* calculate matrix */
index c0aea34ec3569829affc8c4064e153262608be69..1082955b466e07dffee3603166a09b75a0ba6bd7 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, BLI_MEMPOOL_NOP);
-       final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 128, 128, BLI_MEMPOOL_NOP);
+       final_edges->base_pool = BLI_mempool_create(sizeof(ListBase), 0, 128, BLI_MEMPOOL_NOP);
+       final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 0, 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, BLI_MEMPOOL_NOP);
+       hull_pool = BLI_mempool_create(sizeof(HullTriangle), 0, 128, BLI_MEMPOOL_NOP);
        hull_triangles = BLI_gset_ptr_new("hull_triangles");
 
        hull_from_bullet(bm, op, hull_triangles, hull_pool);
index cbe704dbf191b6d1bd3f30fa71e19a554a41d260..b602e0742d0192f15926700f2aab3ac0079d234a 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_NOP);
+       BLI_mempool *edge_state_pool = BLI_mempool_create(sizeof(EdRotState), 0, 512, BLI_MEMPOOL_NOP);
        int i;
 
 #ifdef DEBUG_TIME
index 576d604c1cb464b8dd9da236fb991f3cd9403939..55df5cbc955f6b572382d7b3ac88ae456d8fffd5 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, BLI_MEMPOOL_NOP);
-       BLI_mempool *path_pool = BLI_mempool_create(sizeof(LinkNode), 1, 512, BLI_MEMPOOL_NOP);
+       BLI_mempool *edge_queue_pool = BLI_mempool_create(sizeof(LinkNode), 0, 512, BLI_MEMPOOL_NOP);
+       BLI_mempool *path_pool = BLI_mempool_create(sizeof(LinkNode), 0, 512, BLI_MEMPOOL_NOP);
        LinkNode *edge_queue = NULL;
 
        BMEdge *e;
index cffd38b2a304e66505d482352236b8d40330f011..1fcff82c2a254038baa759b6edb4029fc8988d3b 100644 (file)
@@ -2618,9 +2618,9 @@ static void knifetool_init(bContext *C, KnifeTool_OpData *kcd,
 
        ED_region_tag_redraw(kcd->ar);
 
-       kcd->refs = BLI_mempool_create(sizeof(Ref), 1, 2048, 0);
-       kcd->kverts = BLI_mempool_create(sizeof(KnifeVert), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
-       kcd->kedges = BLI_mempool_create(sizeof(KnifeEdge), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
+       kcd->refs = BLI_mempool_create(sizeof(Ref), 0, 2048, 0);
+       kcd->kverts = BLI_mempool_create(sizeof(KnifeVert), 0, 512, BLI_MEMPOOL_ALLOW_ITER);
+       kcd->kedges = BLI_mempool_create(sizeof(KnifeEdge), 0, 512, BLI_MEMPOOL_ALLOW_ITER);
 
        kcd->origedgemap = BLI_ghash_ptr_new("knife origedgemap");
        kcd->origvertmap = BLI_ghash_ptr_new("knife origvertmap");
index 87043a5581a5a012967741459507b7a81cf447c4..ea75673e5f087741c53a9cba5df8712e7a44738e 100644 (file)
@@ -306,9 +306,9 @@ 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, 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->keys_pool = BLI_mempool_create(sizeof(MovieCacheKey), 0, 64, BLI_MEMPOOL_NOP);
+       cache->items_pool = BLI_mempool_create(sizeof(MovieCacheItem), 0, 64, BLI_MEMPOOL_NOP);
+       cache->userkeys_pool = BLI_mempool_create(keysize, 0, 64, BLI_MEMPOOL_NOP);
        cache->hash = BLI_ghash_new(moviecache_hashhash, moviecache_hashcmp, "MovieClip ImBuf cache hash");
 
        cache->keysize = keysize;