static void outliner_storage_cleanup(SpaceOops *soops) { BLI_mempool *ts = soops->treestore; if (ts) { TreeStoreElem *tselem; int unused = 0; /* each element used once, for ID blocks with more users to have each a treestore */ BLI_mempool_iter iter; BLI_mempool_iternew(ts, &iter); while ((tselem = BLI_mempool_iterstep(&iter))) { tselem->used = 0; } /* cleanup only after reading file or undo step, and always for * RNA datablocks view in order to save memory */ if (soops->storeflag & SO_TREESTORE_CLEANUP) { BLI_mempool_iternew(ts, &iter); while ((tselem = BLI_mempool_iterstep(&iter))) { if (tselem->id == NULL) unused++; } if (unused) { if (BLI_mempool_count(ts) == unused) { BLI_mempool_destroy(ts); soops->treestore = NULL; if (soops->treehash) { BKE_treehash_free(soops->treehash); soops->treehash = NULL; } } else { TreeStoreElem *tsenew; BLI_mempool *new_ts = BLI_mempool_create(sizeof(TreeStoreElem), BLI_mempool_count(ts) - unused, 512, BLI_MEMPOOL_ALLOW_ITER); BLI_mempool_iternew(ts, &iter); while ((tselem = BLI_mempool_iterstep(&iter))) { if (tselem->id) { tsenew = BLI_mempool_alloc(new_ts); *tsenew = *tselem; } } BLI_mempool_destroy(ts); soops->treestore = new_ts; if (soops->treehash) { /* update hash table to fix broken pointers */ BKE_treehash_rebuild_from_treestore(soops->treehash, soops->treestore); } } } } } }
void BLI_edgehash_free(EdgeHash *eh, EdgeHashFreeFP valfreefp) { BLI_assert((int)eh->nentries == BLI_mempool_count(eh->epool)); if (valfreefp) edgehash_free_cb(eh, valfreefp); BLI_mempool_destroy(eh->epool); MEM_freeN(eh->buckets); MEM_freeN(eh); }
/** * Allocate an array from the mempool. */ void *BLI_mempool_as_arrayN(BLI_mempool *pool, const char *allocstr) { void *data = MEM_mallocN((size_t)(BLI_mempool_count(pool) * pool->esize), allocstr); BLI_mempool_as_array(pool, data); return data; }