I don't like slices in D
Jakob Ovrum
jakobovrum at gmail.com
Fri Oct 18 20:46:48 PDT 2013
On Friday, 18 October 2013 at 13:38:01 UTC, Vitali wrote:
> With this in mind I take back everything I said about slices
> and leave only a doubt that slices are performant.
By avoiding the concatenation operators and expansion through
increasing the length property, slices can be used separately
from the runtime's opaque dynamic array type. Slices can be
backed by any memory by slicing a pointer or fixed-length array.
Also, slices with compile-time initializers are backed either by
TLS or global memory.
There is also one incidence in the language where such a
non-runtime-backed slice appears implicitly:
---
void foo(int[] numbers...);
void main()
{
foo([1, 2]); // Uses a GC-managed array for `numbers`
foo(1, 2); // Uses a stack-allocated array for `numbers`
}
---
More information about the Digitalmars-d
mailing list