Setting array length to 0 discards reserved allocation?

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Mon Jul 28 15:28:58 PDT 2014


On 07/27/2014 01:49 AM, Jonathan M Davis wrote:

 > As defined by the language, T[] is a dynamic array.

I bet that terminology is from before the design of slices was finalized 
about four years ago.

 > difference between a dynamic array and a slice (there really isn't any).

At the risk of beating this never-dying horse, when you say that, I 
don't think you can explain the following code:

     int[] a = [ 1, 2, 3 ];
     int[] b = a;

According to your terminology, 'a' is a dynamic array and 'b' is another 
dynamic array. Knowing how good you know D, I can't understand how you 
think that way. In fact, both 'a' and 'b' are slices into the single 
dynamic array. The dynamic array is managed by the GC. So, there are 
three entities in that code: One dynamic array and two slices.

 > IIRC, both Walter and Andrei stated in that discussion that T[]
 > is a dynamic array as far as D is concerned and that's not
 > going to change.

I would like to hear Andrei's and Walter's current opinions on the matter.

 > The article really should be updated to reflect the correct
 > terminology.

It should stay as is to maintain sanity. :)

 > As far as D is concerned a slice and a dynamic array are the
 > same thing when it comes to arrays. They're just different
 > names for T[], and trying to treat them as different just
 > causes confusion.

To me, treating them differently removes all the confusion.

 > - Jonathan M Davis

Ali



More information about the Digitalmars-d mailing list