+#define AUTOEXPAND_BY_REALLOC(ptr, reqitem, allocated, def) \
+ do \
+ { \
+ if(reqitem >= allocated) \
+ { \
+ if(allocated == 0) \
+ allocated = def; \
+ while(reqitem >= allocated && allocated) \
+ allocated *= 2; \
+ if(!allocated || allocated > 2147483647 / sizeof(*ptr)) \
+ { \
+ Error(#ptr " over 2 GB"); \
+ } \
+ ptr = realloc(ptr, sizeof(*ptr) * allocated); \
+ if(!ptr) \
+ Error(#ptr " out of memory"); \
+ } \
+ } \
+ while(0)
+
+#define AUTOEXPAND_BY_REALLOC_BSP(suffix, def) AUTOEXPAND_BY_REALLOC(bsp##suffix, numBSP##suffix, allocatedBSP##suffix, def)
+