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>2019-03-02 12:23:51 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-03-02 12:31:31 +0300
commit10d41e48b8abd6f60f3dc379a8a0b5b5eb4889b4 (patch)
tree6ea8acc356328092f55b9818e53848aeefdf56c1 /source/blender/blenlib/intern/BLI_mempool.c
parentcf75aea218579006262409fd50a239d7b56ce897 (diff)
Fix BLI_mempool incorrect slop-space calculation
Also ensure elements fit evenly into the chunk size causing allocations to be slightly smaller in some cases. In own tests reduces overall memory use by about ~4.5% for high poly meshes in edit-mode.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index a96d4c8b5dd..292cafecc98 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -145,7 +145,7 @@ struct BLI_mempool {
#define NODE_STEP_PREV(node) ((void *)((char *)(node) - esize))
/** Extra bytes implicitly used for every chunk alloc. */
-#define CHUNK_OVERHEAD (uint)(MEM_SIZE_OVERHEAD)
+#define CHUNK_OVERHEAD (uint)(MEM_SIZE_OVERHEAD + sizeof(BLI_mempool_chunk))
#ifdef USE_CHUNK_POW2
static uint power_of_2_max_u(uint x)
@@ -290,18 +290,24 @@ BLI_mempool *BLI_mempool_create(
pool->chunks = NULL;
pool->chunk_tail = NULL;
pool->esize = esize;
- pool->csize = esize * pchunk;
-
/* Optimize chunk size to powers of 2, accounting for slop-space. */
#ifdef USE_CHUNK_POW2
{
- BLI_assert(pool->csize > CHUNK_OVERHEAD);
- pool->csize = power_of_2_max_u(pool->csize) - CHUNK_OVERHEAD;
- pchunk = pool->csize / esize;
+ BLI_assert(power_of_2_max_u(pchunk * esize) > CHUNK_OVERHEAD);
+ pchunk = (power_of_2_max_u(pchunk * esize) - CHUNK_OVERHEAD) / esize;
}
#endif
+ pool->csize = esize * pchunk;
+
+ /* Ensure this is a power of 2, minus the rounding by element size. */
+#ifdef USE_CHUNK_POW2
+ {
+ uint final_size = (uint)MEM_SIZE_OVERHEAD + (uint)sizeof(BLI_mempool_chunk) + pool->csize;
+ BLI_assert(((uint)power_of_2_max_u(final_size) - final_size) < pool->esize);
+ }
+#endif
pool->pchunk = pchunk;
pool->flag = flag;