Faster way of initializing arrays in Delphi
Posted
by Max
on Stack Overflow
See other posts from Stack Overflow
or by Max
Published on 2010-05-12T09:21:56Z
Indexed on
2010/05/12
9:24 UTC
Read the original article
Hit count: 116
delphi
|Performance
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?
© Stack Overflow or respective owner