Array length & allocation question

Derek Parnell derek at psych.ward
Mon Jun 12 15:48:25 PDT 2006


On Tue, 13 Jun 2006 05:27:44 +1000, Bruno Medeiros  
<brunodomedeirosATgmail at SPAM.com> wrote:

> 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?

Agreed, it is not a bug in the sense that it is contrary to specifications  
because this behaviour isn't specified. However it does prevent a coder  
 from distinguishing between an empty array from a null array. An Empty one  
is an array that (no longer) has any elements and a null array is one that  
doesn't have any RAM to reference.

I sugest that Walter either document this functionality or fix it.

"When an array length is reduced the RAM it owns is not released and can  
be reused when the array subsequently is expanded (, unless the length is  
set to zero in which case the RAM is released). "

Setting the length to zero is a convenient way to reserved RAM for an  
array.

Also consider this ...

     foo("");

Now how can 'foo' be written to detect a coder's error of passing it an  
uninitialized array.

     char[] x;
     foo(x);


-- 
Derek Parnell
Melbourne, Australia



More information about the Digitalmars-d-learn mailing list