I need to Initialize an array of unknown size with the index as the value of each element. The obvious solution is to use a loop:
for i:=0 to length(arr)-1 do
arr[i]:=i;
I wonder if there is a faster option?
Thanks
The fastest way would be to not do it at all.
To be less obtuse - if you have a fixed line of modifications you apply to the array afterwards then simply integrate the setting into the first of these calculations. So, instead of
for i:=Low(arr) to High(arr) do
arr[i]:=i;
ModifyStep1(arr);
ModifyStep2(arr);
you change 'ModifyStep1' in a way that it integrates
arr:=i. You can play around with this approach - maybe you need two variants of ModifyStep1, one integrating the setting, one without, etc. Can't comment more specific here, as I don't know your specific requirements.
Cheers,
MathMan