Fixed length vs dynamic arrays
Paul Backus
snarwin at gmail.com
Thu May 6 22:58:00 UTC 2021
On Thursday, 6 May 2021 at 22:35:38 UTC, Alain De Vos wrote:
> Is a fixed length array created on the heap and a dynamic array
> on the stack ? And is this important with relation to the
> garbage collector ?
Static arrays (`T[N]`) are value types, like structs. If you
declare them as local variables, they're allocated on the stack.
Dynamic arrays (`T[]`), also known as slices, are reference
types, consisting of a pointer and a length. If you declare them
as local variables, the pointer and length will be stored on the
stack. The data they point to, however, may be stored on either
the stack or the heap.
For more information about slices in D, I highly recommend this
excellent article by Steven Schveighoffer:
https://dlang.org/articles/d-array-article.html
More information about the Digitalmars-d-learn
mailing list