Slices and Dynamic Arrays

Muld 2 at 2.2
Fri Dec 29 22:47:30 UTC 2017


On Friday, 29 December 2017 at 22:32:01 UTC, Tony wrote:
> In DLang Tour:Arrays
> https://tour.dlang.org/tour/en/basics/arrays
>
> there is:
> -----------------------------------------------
> int size = 8; // run-time variable
> int[] arr = new int[size];
>
> The type of arr is int[], which is a slice.
> -----------------------------------------------
>
> In "D Slices"
> https://dlang.org/d-array-article.html
>
> there is:
> -----------------------------------------------
> int[] a;             // a is a slice
> ------------------------------------------------
>
> Based on those two web pages it appears that the name for a 
> dynamic array <reference?> in D is "slice". That is, anytime 
> you have a dynamic array (even a null reference version) it is 
> called a slice. Is that correct?

Not really, cause you can take a "slice" of a linked list (though 
inefficiently), but a linked list isn't an array. You can also 
take a "slice" of a stack allocated array.



More information about the Digitalmars-d-learn mailing list