## Doubts with Arrays "Dynamic Arrays, On The Fly" multidimensional

Started by Rick, January 11, 2024, 00:11:56

#### Rick

Hello,
I have some doubts with the "Arrays" section, and I was looking at the help of the Blitzmax page.
What I have doubts is in the matrices "Dynamic Arrays, On The Fly". How can I define such a matrix, but multidimensional?

This works well:
Local int_array: int []
int_array = new int [10]

But not this:
Local int_array: int []
int_array = new int [10, 5] '-> 10x5 multidimensional

Thank you. I will surely consult you something else about arrays ...
R.-
== The tRick is that there is no tRick ==

#### Midimaster

There is a possible solution in the cases, when you already know that your array will become a two-dimensional array:

`Local int_array:Int[,]  ' prepare with a commaint_array = New Int [10, 5] '-> 10x5 multidimensional`
During investigating your question, I found a bug...

This will not raise an error message, when I run the code in RELEASE mode:
`Local int_array: Int [,,]int_array = New Int [1, 1, 2] int_array[0,0] = 4  ' <--- call the array with one dimension too small, but no error messagePrint int_array[0,0,0] + " " + int_array[0,0,1]`
...back from Egypt

#### Derron

#2
I guess it is because at the end it uses a simple "1-dimensional" array and just calculates the index based on the given dimensions.
So a bit like the memory block in pixmaps (just that it is not "line + line + line" here but "dim1_value1, dim2_value1, ... dimX_value1, dim1_value2, dim2_value2, ...").

Code (Blitzmax) Select
`Local int_array:Int[1,1,2]int_array[0,0] = 4int_array[1,0,0] = 4`
becomes

Code (C) Select
` BBARRAY bbt_int_array=bbArrayNew("i", 3, 1, 1, 2); BBUINT* bbt_=((BBARRAY)bbt_int_array)->scales + 1; ((BBINT*)BBARRAYDATA(bbt_int_array,1))[(*(bbt_)) * 0U + 0U]=4; BBUINT* bbt_2=((BBARRAY)bbt_int_array)->scales + 1; ((BBINT*)BBARRAYDATA(bbt_int_array,1))[(*(bbt_2)) * 1U + (*(bbt_2+1)) * 0U + 0U]=4;`(the "* xU" is the index used for each dimension ...)

Compiler should possibly check if the amount of "scales" in array definition and array "assignment" is the same.

bye
Ron

#### Rick

#3
I tested the code generated by Mr. Midimaster in BlitzMax "Vanilla" and the compiler warned me about the omission of dimensions, but not BlitzMax NG.
Thanks for all the information, I'm still learning things .
R.-
== The tRick is that there is no tRick ==