Thinking about the difference between fixed and 'dynamic' arrays.
rikki cattermole
rikki at cattermole.co.nz
Tue Nov 29 19:06:20 UTC 2022
Okay you have misunderstand a lot here.
We have two types of arrays:
- Static, fixed sized stored on stack.
- Dynamic, variable sized, stored on the heap.
However dynamic arrays are not actually a distinct type in the type
system, its a language extension to use runtime hooks using the GC.
What dynamic arrays are in the language is just slices.
A slice is a length + pointer pair. This is where almost all of the
syntax for dynamic arrays come from.
```d
int[] slice;
```
That is a slice.
```d
slice ~= 32;
```
Now it is a dynamic array as it was allocated via the GC.
```d
int[4] staticArray;
slice = staticArray[];
```
The slice is now able to modify the staticArray!
More information about the Digitalmars-d-learn
mailing list