Revision: 42182
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42182
Author: campbellbarton
Date: 2011-11-27 01:20:08 +0000 (Sun, 27 Nov 2011)
Log Message:
-----------
mempool utility function to get the element at an index BLI_mempool_findelem(),
not used yet.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_mempool.h
trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
Modified: trunk/blender/source/blender/blenlib/BLI_mempool.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_mempool.h 2011-11-26 21:42:04 UTC
(rev 42181)
+++ trunk/blender/source/blender/blenlib/BLI_mempool.h 2011-11-27 01:20:08 UTC
(rev 42182)
@@ -55,6 +55,7 @@
void BLI_mempool_free(BLI_mempool *pool, void *addr);
void BLI_mempool_destroy(BLI_mempool *pool);
int BLI_mempool_count(BLI_mempool *pool);
+void *BLI_mempool_findelem(BLI_mempool *pool, const int index);
/** iteration stuff. note: this may easy to produce bugs with **/
/*private structure*/
Modified: trunk/blender/source/blender/blenlib/intern/BLI_mempool.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2011-11-26
21:42:04 UTC (rev 42181)
+++ trunk/blender/source/blender/blenlib/intern/BLI_mempool.c 2011-11-27
01:20:08 UTC (rev 42182)
@@ -68,8 +68,9 @@
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_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) {
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs