next up previous contents index
Next: Pointers Up: Arrays Previous: Initialization   Contents   Index

Dynamic Resizing

In an assignment, if an index is given that is ``too large'', the array will be reconfigured so that the new data point will be included. The existing data in the array will remain.

Example

x[2, 4]
x[3, 0] = 2
# The array is now sized as if declared with "x[3,4]"

After the assignment, the maximum index for each dimension will be the larger of the previous index and the assigning index.

When assigning values to an array, dimensional indices that are omitted are taken as zero, though at least one value must be supplied.

Example

x[2, 4]
x[1] = 3
# This is equivalent to x[1,0] = 3

This treatment of missing indices only applies in assignment, and not in general references, as will be seen below.

There is one important restriction on dynamic resizing: arrays that have pointer variables pointing at them can not be resized, and arrays can not be resized through a pointer. Pointers are described below.

The GetDims function can be used to obtain the current dimensions of an array.


next up previous contents index
Next: Pointers Up: Arrays Previous: Initialization   Contents   Index
Stephen R. Whiteley 2024-09-29