Array question about [,] vs [][]

BlitzMax Forums/BlitzMax Programming/Array question about [,] vs [][]

In BMX an array is maintained by keeping track of a pointer to the first element in a continguous block of data. The values of that data is the data in the array. When you do [,] the value is a continguous array of all the data in the entire rectangular array, and some simple math is used to convert the rectangular coordinates to a linear position. But when you use [][], the value of the first array contains pointers to more arrays, which hold your actual data.
A one dimensional array:

array:Int[3]

$00        $01        <- location of array in memory, pointing to $01, the location of the first element
$01        123        <- first element of array, array[0]
$02        456        <- second element of array, array[0]
$03        789        <- third element, array[1]



Then a two dimensional array:

array:Int[3,3]

$00        $01        <- location of array, points to first element at $01
$01        123        <- first element, array[0, 0]
$02        456        <- second element, array[0, 1]
$03        789        <- array[0, 2]
$04        987        <- array[1, 0]
$05        654        <- array[1, 1]
$06        321        <- array[1, 2]
$07        65          <- array[2, 0]
$08        66          <- array[2, 1]
$09        67          <- array[2, 2]



And finally an array of arrays:

array:int[3][3]

$00        $01        <- location of array, points to $01
$01        $04        <- array[0], which points to $04, the location of the values
$02        $07        <- array[1], which points to $07
$03        $0A        <- array[2], which points to $0A
$04        123        <- array[0][0]
$05        456        <- array[0][1]
$06        789        <- array[0][2]
$07        987        <- array[1][0]
$08        654        <- array[1][1]
$09        321        <- array[1][2]
$0A        65          <- array[2][0]
$0B        66          <- array[2][1]
$0C        67          <- array[2][2]

It helps to think about an array as an object, just like any other object like a TList or TImage or whatever. So you can have an array of arrays just like you can have an array of any object like an array of TImage's.

Hope it helps. I was confused at first with the difference, but I read up on it and figured it out.