Re: Merits of different ways of 'extending' arrays [message #85913 is a reply to message #85912] |
Tue, 17 September 2013 14:47  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 9/17/13 1:34 PM, Yngvar Larsen wrote:
> On Monday, 16 September 2013 15:47:38 UTC+1, suicida...@gmail.com
> wrote:
>
>> Allocating and expanding in fixed "blocks" as suggested before is a
>> way to elegantly handle this problem, however the block size needs
>> to be tuned for every application or you can start to get some big
>> slowdowns.
>
> In the generic case when "big enough" is not known, the best
> algorithm is to double the size of the array every time you hit the
> current capacity. (Or 3x or 1.5x, does not matter as long as the
> growth is exponential in as a function of the number of resizes.)
>
> See
>
> http://en.wikipedia.org/wiki/Dynamic_array
>
>
>
This is what MGcoArrayList does.
https://github.com/mgalloy/mglib/blob/master/src/collection/ mgcoarraylist__define.pro
I used to add capacity in increments of a BLOCK_SIZE property set by the
user, but I think the doubling is the way to go.
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|