Dynamic array and slices (need Walter and Andrei decision)

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu May 30 13:19:01 PDT 2013


On 5/30/13 2:25 PM, Maxim Fomin wrote:
> In neighbor thread (especially from 5 page
> http://forum.dlang.org/thread/mailman.175.1369540733.13711.digitalmars-d@puremagic.com?page=5)
> there is discussion about current state of definitions in D related to
> slices, slice expressions and arrays. There is significant contradiction
> between documentation in different parts of the D site and people who
> interpret it.
>
> Problem boils down to following:
>
> - in array and type official spec page, dynamic array is defined as T[]
> type as "Dynamic arrays consist of a length and a pointer to the array
> data.". The page also describes what slicing is. Also expression page
> defines what SliceExpression is. Internally dmd follows these conventions.
>
> - in articles part of the site there is article "D Slices" written by
> Steven Schveighoffer, which abolishes current relevant parts of current
> spec. According to the article, dynamic array is runtime managed memory
> which in implementation specific manner provides some set of operation
> related to arrays. According to the article T[] is by no means a dynamic
> array, but a slice. The article explicitly claims that spec is wrong.
>
> So, there is contradiction between what T[] is. Either it is a slice
> (and what is more important, not a dynamic array type) which point by
> druntime managed dynamic array, or is object of type dynamic array,
> which may point to heap or stack memory.
>
> Discussion shows that there is no clear consensus on this, so there is
> need for Walter and Andrei to comment on this.

T[] is both. You can use it to take a slice of any piece of memory, 
including freshly GC-allocated arrays. But when you try e.g. to append 
to it with ~=, that only works if the slice originated as a GC-allocated 
array.

Andrei


More information about the Digitalmars-d mailing list