[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23185] trunk/blender/source/blender/ blenkernel/BKE_utildefines.h: forgot this

Joseph Eagar joeedh at gmail.com
Sun Sep 13 18:24:06 CEST 2009


Revision: 23185
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23185
Author:   joeedh
Date:     2009-09-13 18:24:06 +0200 (Sun, 13 Sep 2009)

Log Message:
-----------
forgot this

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_utildefines.h

Modified: trunk/blender/source/blender/blenkernel/BKE_utildefines.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_utildefines.h	2009-09-13 16:15:26 UTC (rev 23184)
+++ trunk/blender/source/blender/blenkernel/BKE_utildefines.h	2009-09-13 16:24:06 UTC (rev 23185)
@@ -193,5 +193,54 @@
 #define SET_INT_IN_POINTER(i) ((void*)(intptr_t)(i))
 #define GET_INT_FROM_POINTER(i) ((int)(intptr_t)(i))
 
+/*little array macro library.  example of usage:
+
+int *arr = NULL;
+V_DECLARE(arr);
+int i;
+
+for (i=0; i<10; i++) {
+	V_GROW(arr);
+	arr[i] = something;
+}
+V_FREE(arr);
+
+arrays are buffered, using double-buffering (so on each reallocation,
+the array size is doubled).  supposedly this should give good Big Oh
+behaviour, though it may not be the best in practice.
+*/
+
+#define V_DECLARE(vec) int _##vec##_count=0; void *_##vec##_tmp
+
+/*in the future, I plan on having V_DECLARE allocate stack memory it'll
+  use at first, and switch over to heap when it needs more.  that'll mess
+  up cases where you'd want to use this API to build a dynamic list for
+  non-local use, so all such cases should use this macro.*/
+#define V_DYNDECLARE(vec) V_DECLARE(vec)
+
+/*this returns the entire size of the array, including any buffering.*/
+#define V_SIZE(vec) ((signed int)((vec)==NULL ? 0 : MEM_allocN_len(vec) / sizeof(*vec)))
+
+/*this returns the logical size of the array, not including buffering.*/
+#define V_COUNT(vec) _##vec##_count
+
+/*grow the array by one.  zeroes the new elements.*/
+#define V_GROW(vec) \
+	V_SIZE(vec) > _##vec##_count ? _##vec##_count++ : \
+	((_##vec##_tmp = MEM_callocN(sizeof(*vec)*(_##vec##_count*2+2), #vec " " __FILE__ " ")),\
+	(vec && memcpy(_##vec##_tmp, vec, sizeof(*vec) * _##vec##_count)),\
+	(vec && (MEM_freeN(vec),1)),\
+	(vec = _##vec##_tmp),\
+	_##vec##_count++)
+
+#define V_FREE(vec) if (vec) MEM_freeN(vec);
+
+/*resets the logical size of an array to zero, but doesn't
+  free the memory.*/
+#define V_RESET(vec) _##vec##_count=0
+
+/*set the count of the array*/
+#define V_SETCOUNT(vec, count) _##vec##_count = (count)
+
 #endif
 





More information about the Bf-blender-cvs mailing list