Array and loading with LoadByteArray
BlitzMax Forums/BlitzMax Beginners Area/Array and loading with LoadByteArray
| ||
I just discovered that in order to create a multidimensionnal array variable, you have to declare like this: Field map:Byte[,] ..and later in the code you can do this: map = New Byte[width, height] ..which is pretty nice. But I couldn't find anything in the documentation helping understanding that topic. Interestingly, omitting the ',' from the first declaration will make the compiler spit out a paradoxal message: Unable to convert from 'Byte Array' to 'Byte Array' Now the real question: is there a better (more optimal) way of loading a two dimension map than reading it byte per byte like this: map = New Byte[width, height] For Local j = 0 Until height For Local i = 0 Until width map[i,j] = ReadByte(loadmap) Next Next I know that LoadByteArray can load a file in one shot, but it will always create a new one dimension array to return its value, and also have the limitation of always reading until the end of file, which might not be desired. I know also that using Bank, I could do a PeekByte() loop instead, but that would probably be approximatively the same performance. There should be a more flexile generic method like: Function ReadMultiByte:Byte[](stream: TStream, count: TInt) or even one that would read directly into an existing array (but that's more C-ish, and maybe not safe enough for BlitzBasic taste), like: Function ReadMultiByteInPlace(stream: TStream, count: TInt, destination:Byte ptr) |