DIP 1025--Dynamic Arrays Only Shrink, Never Grow--Community Review Round 1
Dennis
dkorpel at gmail.com
Mon Nov 11 13:13:39 UTC 2019
On Monday, 11 November 2019 at 11:26:49 UTC, Nicholas Wilson
wrote:
> is functional identical, thus any issues present in 2 are also
> present in 1. The suggestion that doing so in a loop would
> create more garbage is false as it is functionally identical.
There is a difference: a = a ~ b is guaranteed to make a copy
while a ~= b might just use spare capacity of the memory that
slice `a` refers to.
https://dlang.org/spec/arrays.html#array-concatenation
This is what the dead/alive example is supposed to express.
It is still true however that the rationale is not very
convincing.
The first example indeed doesn't show any benefits of the DIP:
```
int[] slice = cast(int*)malloc(10 * int.sizeof)[0 .. 10];
slice = slice ~ 1; // now guaranteed to make a copy
free(slice.ptr); // Still oops
```
The following claim in the DIP is also unsubstantiated:
> This change is a necessary part of D evolving towards being
> memory safe without using
> a GC.
I would like to see an example of memory corruption in `@safe`
code that can happen because of slice appending.
More information about the Digitalmars-d
mailing list