On Thursday, 30 May 2013 at 20:19:01 UTC, Andrei Alexandrescu
wrote:
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
It actually works with any slice and will create a new
GC-allocated array and point to that for non-GC allocated arrays.
void main()
{
char* a = cast(char*) malloc(5);
auto slice_a = a[0..5];
slice_a ~= char.init;
assert(slice_a.ptr != a);
}