<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr">Mark Morgan Lloyd <<a href="mailto:markMLl.fpc-pascal@telemetry.co.uk">markMLl.fpc-pascal@telemetry.co.uk</a>> schrieb am Do., 7. Juni 2018, 11:46:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 04/06/18 12:00, Nitorami wrote:<br>
>>> It would be reasonable to assume that the predefined + might be>> substantially more efficient than a programmer-defined one could be.<br>
>> Yes, that's one of the reasons I vote for keeping the new feature>and allow to overload the operator.<br>
> I don't think that argument holds water. Concatenation of dynamic structuresis a slow function in the first place. I am not a core developer, but Iconsider that regardless how you do it, it will require a call to setlength,which in turn will call the operating system to allocate memory for the nowlarger structure. That takes much more time than a few assembly instructionsfor a normal pascal procedure call.<br>
<br>
The obvious workaround is to preallocate a dynamic array to a nominal <br>
size and then to trim it using SetLength(0), I'd assumed that it would <br>
retain ownership of the memory but I've just checked.<br>
<br>
What actually happens is that the memory is released back to the heap <br>
(but *not* to the OS, at least on Linux), with the result that <br>
concatenating elements will introduce a substantial hit particularly if <br>
space for a new element allocated from the heap isn't contiguous.<br></blockquote></div><div dir="auto"><br></div><div dir="auto">Of course SetLength(0) releases the memory as the value of a dynamic array with length 0 is Nil, so nothing can be saved there. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven</div><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div>