Array length & allocation question

Lars Ivar Igesund larsivar at igesund.net
Thu Jun 8 10:52:36 PDT 2006


Sean Kelly wrote:

> Robert Atkinson wrote:
>> Quick question concerning Array lengths and memory allocations.
>> 
>> When an array.length = array.length + 1 (or length - 1) happens, does the
>> system only increase (decrease) the memory allocation by 1 [unit] or does
>> it internally mantain a buffer and try to minimise the resizing of the
>> array?
> 
> The latter.
> 
>> I think I can remember seeing posts saying to maintain the buffer
>> yourself and other posts saying it was done automatically behind the
>> scenes.
> 
> In most cases it's not worth it to try and maintain the buffer yourself.
>   At the very least, you should test both methods and see which is faster.
> 
> 
> Sean

I think the "double-the-size-when-more-is-needed" strategy is used, and
afaik, it is the one that performs best in the general case.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource & #D: larsivi



More information about the Digitalmars-d-learn mailing list