Fast Array Loading

BlitzMax Forums/BlitzMax Programming/Fast Array Loading

Is there a way to create an array in this manner?
MyArray[9] = {0,1,2,3,4,5,6,7,8}


From the doc
'Auto arrays' may be created using the syntax:
[Element1,Element2 etc...]

This returns a 1 dimensional array containing the specified elements, for example:

Local int_array[]=[1,2,3,4,5]

Each element of an auto array must have exactly the same type. If necessary, you can use type conversions to enforce this.



Bascially use square brackets on the right hand side of the = and don't specify the size of the array.

But it is not faster. This is actually calling the slicing mechanics and is slower than initializing the array with new and handfilling it!

When you say 'Not faster' do you mean to process or to input?
I would guess that the number of items you'd have to add to make any difference in processing would mean it was NOT a good idea to enter them in the 'Auto array' fashion anyway.

It is not faster program execution wise.

Typing a few letters does not make a difference to me, even if I handfill a 4x4 matrix.
But if you play lazy ass you will learn that the compiler does not replace that with a more performance friendly construct (ie my handwritten one) and that you will lose a fair amount of performance.

No problem for a single instance array, there I wouldn't use the handwrite approach

But for vectors and the like (speed critical), this approach is plain wrong and defeats the purpose of optimized math routines.

I'm just setting the initial values and they won't change.

Hmm...this is throwing an Int to Float error:
Local myarray:Float[] = [0,1,2,3,4,5,6,7,8]


EDIT: Nm, I fixed it.
Local myarray:Float[] = [0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0]