Setting array length to 0 discards reserved allocation?
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 29 22:55:57 PDT 2014
On Wednesday, 30 July 2014 at 02:08:30 UTC, Andrew Godfrey wrote:
> fyi, here's what I have so far.
> I haven't yet added the cross-references we talked about at the
> start of the thread. I'll be away for a few weeks soon, so
> won't have much more time until after that.
>
> I'm hoping this link is public. It seemed public:
>
> https://github.com/AndrewGodfrey/dlang.org/commit/463b5656151616e2a164ad414cf2bd61d1b84beb
I'm completely opposed to changing the official terminology. Per
both the spec and TDPL T[] is both a dynamic array and a slice,
and I see no reason to change that. And as far as I can tell it's
in line with how dynamic arrays are described on Wikipedia:
https://en.wikipedia.org/wiki/Dynamic_array
It's just that the dynamic arrays in D do not own their own
memory, and it's the GC which manages dealing with expanding the
memory with amortized cost. So, as far as I can tell, T[] follows
the expected semantics of dynamic arrays with a few extra
capabilities tacked on.
What does trying to change the terminology buy you? Having it be
more in line with the array article? If anything, the article
should be updated to match the official terminology, not change
the terminology to match the article.
It's correct to say that T[] is a slice, because it's always a
slice of some chunk of memory - be it from the GC, a static
array, malloc, etc. And it's correct to say that T[] is a dynamic
array, because it supports all of the operations that a dynamic
array is supposed to support. It just comes with the added
benefit of being able to have multiple arrays refer to the same
memory until one of them has to reallocate due to a lack of
available capacity (which is exactly how dynamic arrays work in
other languages when you append to them and they don't have
enough available space to grow in place).
I do not understand how any of you can claim that T[] is not a
dynamic array. Just because it doesn't manage its own memory? The
GC manages it in a manner that gives T[] all of the expected
semantics of a dynamic array with the added benefit that we can
even append onto a dynamic array that's a slice of
non-GC-allocated memory (though that makes it so that it is then
GC-allocated when it gets reallocated). What about T[] is _not_ a
dynamic array?
- Jonathan M Davis
More information about the Digitalmars-d
mailing list