Setting array length to 0 discards reserved allocation?
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jul 27 05:03:01 PDT 2014
On Sunday, 27 July 2014 at 09:10:26 UTC, Jakob Ovrum wrote:
> On Sunday, 27 July 2014 at 08:49:43 UTC, Jonathan M Davis wrote:
>> As defined by the language, T[] is a dynamic array. As great
>> as the article is, it was wrong in its use of the terminology,
>> and that's what's caused a lot of the confusion and resulted
>> in arguments over the difference between a dynamic array and a
>> slice (there really isn't any). 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. The article
>> really should be updated to reflect the correct terminology.
>> 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.
>
> Conflating both concepts with the same name is why the article
> was so dearly needed in the first place.
Except that no concepts are being conflated. T[] is the dynamic
array. There's a block of memory managed by the GC underneath,
but it's completely hidden from the programmer. It is _not_ the
dynamic array. It's just a block of memory managed by the GC
which is used to manage the memory for dynamic arrays, and it has
a completely different type from T[]. It's not even an array in
the D sense. The block of memory is referred to by a pointer, not
a D array.
It's talk of "which array" owns the memory and the like which
causes confusion, and talking about the GC-managed block of
memory as being the dynamic array and the T[] that the programmer
sees as being the slice is just plain wrong. The T[] is both a
slice and a dynamic array (because they're the same thing),
whereas the block of memory is neither. I think that the fact
that the article tried to call the underlying block of memory a
dynamic array has caused a lot of unnecessary confusion.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list