Local Value Arrays
If the number of new locals to be protected is unknown at compile you can use the following macros that create protected arrays of values. One form creates the array on the stack using \_alloc()
and so is useful inside one function call, the other puts the array in the heap and so can be used across functions. In both cases, you also need to declare a Value
** variable to hold the pointer to the array.
Stack-resident Array
value_local_array
- allocates the array ofValue
* variablespop_value_local_array
- dismisses the array ofValue
* variables
Heap-resident Array
value_temp_array
- allocates the array ofValue
* variablesrealloc_value_temp_array
- resizes the arraypop_value_temp_array
- dismisses the array
Example
Value** items;
value_local_array(items, n);
for (int i = 0; i < n; i++)
items[i] = Float::intern(data[i]);
pop_value_local_array(items);