arrays in blitzmax
BlitzMax Forums/BlitzMax Beginners Area/arrays in blitzmax
| ||
Hi, I'm totally new to blitzmax. I need to resize a couple of arrays but the changes from blitz3d have confused me. Is everything automatic with arrays now? I can't find any useful information about them in the docs. Could someone please do a quick example of a 1-D array, a 2-D one, and how to resize them? I'm used to something like this: DIM array1%(100) DIM array2%(100,100) Then to resize them at a later point I'd just DIM them again. Or is my memory playing tricks? I have managed to create 1D arrays which are doing the job, but a resizeable 2D one would be ideal. thanks in advance |
| ||
This should do what you're afterLocal a:Byte[100,100] a = New Byte[50,50] The old array is free'd and the memory for it released when you next call FlushMem Aaron |
| ||
That's exactly what I needed, thanks. Simple :) |
| ||
If you want to extend an array, keeping the contents of it, you can do it this way:Local MyArray:Int[20, 50] MyArray = MyArray[.. 21, .. 51] This way, the "slice" operator (..) extends the array to have one more field in each dimension, and the array is stored in the same variable that previously handled it. |
| ||
That's handy, no need to back up the contents before resizing. From what I've read so far about slices, i looks like you could add or remove elements at either end of the array without losing data. I don't need it just now but I've a lot of Blitz3d code that would have benefitted from that ability. |
| ||
I've always wondered why the slice thingy uses the same symbol ".." as the line break thingy... just seems a bit... odd. |