@@ -29,7 +29,8 @@ constant int MAX_FREE_SECTIONS = 256
2929 * ========================
3030 * Each ArrayList<T> type gets its own static storage array.
3131 * - ArrayList<int>, ArrayList<unit>, ArrayList<string> = 3 separate arrays
32- * - Each type can hold up to JASS_MAX_ARRAY_SIZE elements total across all instances
32+ * - On the Jass target each type holds up to JASS_MAX_ARRAY_SIZE elements total across all
33+ * instances (the Lua target grows dynamically and is not bounded by this)
3334 *
3435 * Choose wisely based on how many types you have.
3536 *
@@ -87,11 +88,12 @@ constant int MAX_FREE_SECTIONS = 256
8788 * Fragmentation occurs when lists grow - the old section becomes a gap.
8889 * This is why presizing matters: growth = copy to new location = wasted space.
8990 *
90- * Hard limit (wc3 native-array target): the shared store is bounded by
91- * JASS_MAX_ARRAY_SIZE total slots per type across all live instances; exceeding
92- * it raises an error. On the Lua target the backing store grows dynamically, so
93- * this cap does not apply - there ArrayList is still valuable mainly for keeping
94- * element types static instead of relying on typecasting.
91+ * Hard limit (wc3 / Jass native target): the shared store is a fixed-size array, so it is
92+ * bounded by JASS_MAX_ARRAY_SIZE total slots per type across all live instances; exceeding
93+ * it raises an error. On the Lua target the store is a dynamically growing table, so the
94+ * cap does not apply - allocateStorage branches on the magic isLua constant and skips the
95+ * error. ArrayList's added value on Lua is keeping element types static instead of relying
96+ * on typecasting.
9597 **/
9698public class ArrayList<T:>
9799 private static T array store
@@ -139,10 +141,12 @@ public class ArrayList<T:>
139141
140142 // No suitable free section, allocate new
141143 if nextFreeIndex + cap > JASS_MAX_ARRAY_SIZE
142- // Try to compact free sections
144+ // Past the native array bound - compact to reclaim trailing freed space first
143145 compactFreeList()
144146
145- if nextFreeIndex + cap > JASS_MAX_ARRAY_SIZE
147+ // The Jass target is a fixed-size array and must error here. On Lua the store
148+ // is a dynamically growing table, so the bound doesn't apply and we let it grow.
149+ if not isLua and nextFreeIndex + cap > JASS_MAX_ARRAY_SIZE
146150 error("ArrayList: Storage limit exceeded for type")
147151
148152 startIndex = nextFreeIndex
0 commit comments