resize array

BlitzMax Forums/BlitzMax Beginners Area/resize array

Nate the Great(Posted 2009) [#1]
Hey,

I have been trying for a while to find out how to resize multi-dimensional arrays and I just can't figure it out.

My array looks like this

array[100,100]

and say I want to resize it to 200,200

I assumed you would do this: array = array[..200,200] but that doesnt work so what will? I also can't find it in the docs anywhere


Jesse(Posted 2009) [#2]
As far as I know it it works with one dimension only. You should be able to handle that on your own. It doesn't seem too hard to tackle.


Otus(Posted 2009) [#3]
You can avoid a lot of problems by using arrays of arrays instead of multidimensional ones. Like Jesse said, you need to write the code yourself - create a larger array, copy the contents.


Nate the Great(Posted 2009) [#4]
ok thanks... I just thought maybe there was a way around it.. I have heard 1 dimensional arrays are faster anyway.


ImaginaryHuman(Posted 2009) [#5]
Yeah you can't slice a multidimensional array. You can define a whole new array with the new dimesions and then manually copy the contents. Otherwise an array of arrays works well - you can then slice each individual array.

A one dimensional array will be faster than a multidimensional one, given that in a multidimensional array, each dimension adds an array of separate memory blocks, each with their own base pointer, thus requiring two indirect jumps to get to an element. Also, if you're thinking of your first dimension as X and your second dimension as Y, for as many Y dimensions as the size of X, there will be that many separate memory areas needed, which means if you're jumping about in the multidimensional array it will scatter the accesses across memory, which could give poor cache performance.


N(Posted 2009) [#6]
given that in a multidimensional array, each dimension adds an array of separate memory blocks
Assuming you mean that it's allocating separate blocks for each dimension, that would be incorrect. BMax seems to only allocate one large block for a multidim array.