Rezising Arrays and getting Array Sizes

BlitzMax Forums/BlitzMax Beginners Area/Rezising Arrays and getting Array Sizes

Mordax_Praetorian(Posted 2006) [#1]
Firstly, I have a 2D Array, of which I would like to increase the size of 1 dimension, saving the data already there

Secondly, I need to be able to grab the current size of that dimension, for use in For loops etc

The only way I have found to get the size of a dimension is to have an extra element with some sort of marker in it, and loop until that marker is found

If there is an easier way I would rather use that

And whilst resizing a 1D array isnt hard, resizing a 2D one is more difficult

I could probably come up with the solution myself given enough time, but since I cant find the info here I figured it'd be useful to gather the various methods up in 1 place where people could find them


Perturbatio(Posted 2006) [#2]
an Array of arrays is probably your best bet.

http://www.blitzwiki.org/index.php/Arrays#Resizing_an_Array_of_Arrays


Mordax_Praetorian(Posted 2006) [#3]
Interesting

I'll give that a spin


H&K(Posted 2006) [#4]
Th way I find the size of an array, is to simply keep track of how big it is. And everytime I resize the array, change the variable with the size of the array to the new size


Mordax_Praetorian(Posted 2006) [#5]
That works, I just throw it into a List and count the size of that, but it doesnt quite work with a 2D one, since Lists as far as I know are 1D

I'm still playing around with Arrays within Arrays, not quite sure if its what I'm after yet though


Mordax_Praetorian(Posted 2006) [#6]
I tried to make an array of arrays without auto initialisation, and it keeps saying "Incorrect number of array dimensions"

Is there a way to create Arrays of Arrays without auto-initialisation?


Perturbatio(Posted 2006) [#7]
Th way I find the size of an array, is to simply keep track of how big it is. And everytime I resize the array, change the variable with the size of the array to the new size


Wouldn't it make more sense to use Len?

Local a:Int[2,2,2]
Print Len(a)


'm still playing around with Arrays within Arrays, not quite sure if its what I'm after yet though


If you can get your head around it (some people don't quite click straight away), then it's easy and will definitely do what you want.

As BMax stands, you can't resize a multi-dimensional array.


H&K(Posted 2006) [#8]
@Pert,
Wouldn't it make more sense to use Len?

Yes it probably would. But I still always keep track of the array size in an asociated variable
Local a:int[23,55,3]
local asize:Int[]=[23,55,3]
Even when I think Im never going to resize


Mordax_Praetorian(Posted 2006) [#9]
There are some very strict conditions that they need to meet

What I'm dealing with is data on animations, its pretty complex stuff that I'm not sure I have the words to explain, I can only think about the system myself in pictures... its quite bizzare

But basicly, It'd be shrinking to a 0,0 array quite often, so it needs to survive that

Auto-Initialisation is also out, I need to create the array through other means


BlackSp1der(Posted 2006) [#10]
you can use dimensions() to get the array dimensions. :S
Strict

Local array:Int[20,33,4,10,6]

Print "Total Dimensions = "+array.Dimensions().Length
For Local dim:Int=0 Until array.Dimensions().Length
	Print "Dimension "+(dim+1)+" Length = "+array.Dimensions()[dim]
Next



H&K(Posted 2006) [#11]
It doesnt matter if you can find the dimensions or not, I always keep track of how big the array is supposed to be.
The same way as I always have globaled the current screen size, even tho that can be found just as easly.