[fpc-pascal] performance when resizing a dynamic array

Dmitry Boyarintsev skalogryz.lists at gmail.com
Sun Dec 4 15:10:17 CET 2016


On Sun, Dec 4, 2016 at 5:28 AM, Graeme Geldenhuys <
mailinglists at geldenhuys.co.uk> wrote:

> If I use an array to hold a list of say Integers. Is there any serious
> performance penalty for resizing (growing) the dynamic array as I add
> items. My point being, I don't know the number of elements I'll need
> beforehand.
>

Power of 2 increments then (less re-allocations, less memory
fragmentation).
You'll also need to store the actual size somewhere next to the dynamic
array, since you can no longer rely on length()

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20161204/a7d8fe21/attachment.html>


More information about the fpc-pascal mailing list