array of arrays

BlitzMax Forums/BlitzMax Beginners Area/array of arrays

yossi(Posted 2014) [#1]
when I try to declare array of arrays at the static way it works fine:
Local x:int[][]=[[1,2],[3],[4,5,6]]

but when I try to do the same think in more dynamic way I get an error:
Local x:Int[][]
x=New Int[3] 'i want do create 3 arrays
x[0]=New Int[2] 'the first array include 2 cells
x[1]=New Int[1] 'the second array include 1 cell
x[2]=New Int[3] 'the third array include 3 cells

it seems to me that array of arrays must be declared with all of it's values at the beginning and cant be created dynamicly and if it works like that it miss all the point because array of arrays actually come to save memory (creating sum arrays with a different dimension).
if memory saving is not an issue we can always declare multi dimensional array and set the dimensions to the maximum we need even if we not need it in all cases.


Floyd(Posted 2014) [#2]
Local x:Int[][]
x=New Int[][3] 'i want do create 3 arrays
x[0]=New Int[2] 'the first array include 2 cells
x[1]=New Int[1] 'the second array include 1 cell
x[2]=New Int[3] 'the third array include 3 cells


Notice that x=New Int[3][] will not work.

I suppose the way to think about this is that x:Int would be an integer.
x:Int[] would be an array. The [] at the end means array, and the type is given by the Int before the []

So Int[][3] is a three element array. The type is Int[].


yossi(Posted 2014) [#3]
thank you very much.
it was very helpful.