Note that there are some explanatory texts on larger screens.

plurals
  1. POFaster way of initializing arrays in Delphi
    primarykey
    data
    text
    <p>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 </p> <p>SetLength(Result, Len);</p> <p>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:</p> <p>_DynArraySetLength -> DynArraySetLength</p> <p>DynArraySetLength gets the array length (which is zero for initialization) and then uses ReallocMem which is also unnecessary for initilization.</p> <p>I was doing SetLength to initialize dynamic array all the time. Maybe I'm missing something? Is there a faster way to do this?</p> <p>EDIT: Describing the main algorithm would take a lot of space and really is unnecessary because it'm trying to optimize a small part of it. In general terms it's a veriant of Vehicle Routing Problem (<a href="http://en.wikipedia.org/wiki/Vehicle_routing_problem" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Vehicle_routing_problem</a>). I do need zillions of allocations, because I have to keep all the data, and keep it separately. Probalby it would help if I could think of some clever data structure here, but anything I can think of would greatly increase the complexity of the code. Basically I've done everything I could on the algorithmic level, so now I'm trying to get everything I can from the lowlevel things. So this is rather narrow question: is there any possibility to increase this particular call. And I think that to do this I need to write my own initialization function based on the SetLength code. And make it inline.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload