Array length & allocation question

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Sun Jun 11 16:11:04 PDT 2006


Lars Ivar Igesund wrote:
> 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.
> 

Hum, and happens when one shortens the length of the array? The Memory 
Manager "back" buffer size remains the same?

-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d-learn mailing list