Array length & allocation question

Oskar Linde oskar.lindeREM at OVEgmail.com
Mon Jun 12 13:04:26 PDT 2006


Bruno Medeiros skrev:
> Derek Parnell wrote:
>> On Mon, 12 Jun 2006 09:11:04 +1000, Bruno Medeiros 
>> <brunodomedeirosATgmail at SPAM.com> wrote:
>>
>>> Hum, and happens when one shortens the length of the array? The 
>>> Memory Manager "back" buffer size remains the same?
>>
>> Yes. However there is a bug (oops - an issue) in which if the length 
>> is set to zero the RAM is released back to the the system.
>>
>> --Derek Parnell
>> Melbourne, Australia
> 
> That makes perfect sense, why would it be a bug?
> 

I don't know if this is what Derek refers to, but it used to be 
recommended practice to reserve space for an array by doing:

arr.length = 1024;
arr.length = 0;
(start filling arr with data)

I'm quite sure this used to be mentioned in the documentation, but I can 
no longer find any reference to it (except this old post: 
http://www.digitalmars.com/drn-bin/wwwnews?D/17691)

Today, I guess you should do the following instead:

arr.length = 1024;
arr = arr[0..0];
(start filling arr with data)

/Oskar



More information about the Digitalmars-d-learn mailing list