D LanguageDynamic Arrays & Slices


Syntax

  • <type>[] <name>;

Remarks

Slices generate a new view on existing memory. They don't create a new copy. If no slice holds a reference to that memory anymore - or a sliced part of it - it will be freed by the garbage collector.

Using slices it's possible to write very efficient code for e.g. parsers that just operate on one memory block and just slice the parts they really need to work on - no need allocating new memory blocks.