On Friday, 1 August 2014 at 06:18:06 UTC, Jonathan M Davis wrote:
On Wednesday, 30 July 2014 at 06:11:58 UTC, Dominikus Dittes
Scherkl wrote:
[...]
should go in the official terminology. (otherwise we would
need a new, third term to describe the "other thing" that is
not directly accessible in the current language spec wording -
but we have none and it would only increase the confusion).
The "other thing" is just a block of memory managed by the GC
and which keeps track of the farthest into the block a
particular slice / dynamic array has grown. It doesn't actually
act like a dynamic array at all, because it doesn't ever grow.
Really?
If I append to my slice, a new "just block of memory" gets
allocated, data copied there and my reference changed to point to
this new block. Isn't that what everybody describes as that what
a dynamic array does?
Ok, I'm not absolutely sure which part of the runtime performs
these changes - if it is the GC or the opAppend of arrays or
whatever, but the block of memory together with these operations
is really what I would call a "dynamic array".
It's just used by the GC to provide memory for dynamic arrays
and is only associated with a particular dynamic array until
that array is reallocated. Calling that block of memory a
dynamic array would be like calling the guts of a std::vector a
dynamic array instead calling std::vector a dynamic array. It's
just the memory and bookkeeping that backs the dynamic array.
If a distinction between vector and its backing would be useful,
yes I would say it is reasonable to call the backing "dynamic
array".
And dynamic array and slice are already not entirely the same,
because of more general slicing operations. A dynamic array is
always a slice, but if you're talking about the language in
general and not arrays specifically, a slice could be something
else - e.g. you can slice a DList to get a range over it. It's
less common that those are referred to as slices, but they
essentially are, and you use opSlice to get them.
Nice. So we have slices with dynamic array as background and we
have slices with different background - even more reason to
distinguish slice and dynamic array cleanly.
I'm increasingly tempted to just write up a new article that
uses the correct terminology. And if I can do that properly,
then maybe it'll help clear up the confusion.
Yes, do that. I'm eager to read it and see, if it is still as
enlightening as the old article was.