Mark Morgan Lloyd <markmll.fpc-pas...@telemetry.co.uk> schrieb am Do., 7.
Juni 2018, 11:46:

> On 04/06/18 12:00, Nitorami wrote:
> >>> It would be reasonable to assume that the predefined + might be>>
> substantially more efficient than a programmer-defined one could be.
> >> Yes, that's one of the reasons I vote for keeping the new feature>and
> allow to overload the operator.
> > 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.
>
> The obvious workaround is to preallocate a dynamic array to a nominal
> size and then to trim it using SetLength(0), I'd assumed that it would
> retain ownership of the memory but I've just checked.
>
> What actually happens is that the memory is released back to the heap
> (but *not* to the OS, at least on Linux), with the result that
> concatenating elements will introduce a substantial hit particularly if
> space for a new element allocated from the heap isn't contiguous.
>

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.

Regards,
Sven

>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to