Slices and Dynamic Arrays

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Jan 1 02:10:14 UTC 2018


On Sunday, December 31, 2017 14:49:40 Tony via Digitalmars-d-learn wrote:
> On Sunday, 31 December 2017 at 14:24:40 UTC, Jonathan M Davis
>
> wrote:
> > The D Slices article does an excellent job of explaining all of
> > this. It's just that it calls the GC-allocated memory buffer
> > the dynamic array instead of calling T[] the dynamic array like
> > the language and spec do. Regardless, all non-null dynamic
> > arrays are slices of memory.
>
> The DLang Tour also uses the term slice to refer to T[].
>
> "The type of arr is int[], which is also called a slice."
>
> "A slice consists of two members - a pointer to the starting
> element and the length of the slice:"

Presumably, because whoever wrote that preferred the terminology used in the
D Slices article. Regardless, it's not wrong to call them slices. It's just
less precise, since the term slice refers to more than dynamic arrays.

The DLang Tour should probably be fixed to use the term dynamic array
though.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list