diff options
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 7dc43bb1494..a37a7781286 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -121,10 +121,14 @@ struct BLI_mempool { /** * \return the number of chunks to allocate based on how many elements are needed. + * + * \note for small pools 1 is a good default, the elements need to be initialized, + * adding overhead on creation which is redundant if they aren't used. + * */ BLI_INLINE unsigned int mempool_maxchunks(const unsigned int totelem, const unsigned int pchunk) { - return totelem / pchunk + 1; + return (totelem <= pchunk) ? 1 : ((totelem / pchunk) + 1); } static BLI_mempool_chunk *mempool_chunk_alloc(BLI_mempool *pool) |