Faster way of initializing arrays in Delphi
- by Max
I'm trying to squeeze every bit of performance in my Delphi application and now I came to a procedure which works with dynamic arrays. The slowest line in it is
SetLength(Result, Len);
which is used to initialize the dynamic array. When I look at the code for the SetLength procedure I see that it is far from optimal. The call sequence is as follows:
_DynArraySetLength - DynArraySetLength
DynArraySetLength gets the array length (which is zero for initialization) and then uses ReallocMem which is also unnecessary for initilization.
I was doing SetLength to initialize dynamic array all the time. Maybe I'm missing something? Is there a faster way to do this?