diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-11-27 05:20:08 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-11-27 05:20:08 +0400 |
commit | 8423b1b33a51ecc45480d664e4bba7e488eac704 (patch) | |
tree | 16ded9fede452f793cdbb58c65b009615783ea1f /source/blender/blenlib/intern/BLI_mempool.c | |
parent | 65cf6256f5e08d8fb1897c3f67375aa67b72a523 (diff) |
mempool utility function to get the element at an index BLI_mempool_findelem(), not used yet.
Diffstat (limited to 'source/blender/blenlib/intern/BLI_mempool.c')
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 19ae89da8ea..f8da524d097 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -68,8 +68,9 @@ typedef struct BLI_mempool_chunk { struct BLI_mempool { struct ListBase chunks; - int esize, csize, pchunk; /* size of elements and chunks in bytes - * and number of elements per chunk*/ + int esize; /* element size in bytes */ + int csize; /* chunk size in bytes */ + int pchunk; /* number of elements per chunk */ short use_sysmalloc, allow_iter; /* keeps aligned to 16 bits */ @@ -240,6 +241,23 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr) } } +void *BLI_mempool_findelem(BLI_mempool *pool, const int index) +{ + if ((index >= 0) && (index < pool->totused)) { + BLI_mempool_chunk *mpchunk; + int i= 0; + + for (mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) { + if (index < i + pool->pchunk) { + return ((char *)mpchunk->data) + (pool->esize * (index - i)); + } + i += pool->pchunk; + } + } + + return NULL; +} + void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) { if (!pool->allow_iter) { |