DIP 1025--Dynamic Arrays Only Shrink, Never Grow--Community Review Round 1

Steven Schveighoffer schveiguy at gmail.com
Mon Nov 11 22:04:17 UTC 2019

On 11/11/19 4:54 PM, Jonathan M Davis wrote:
> On Monday, November 11, 2019 2:34:39 PM MST Walter Bright via Digitalmars-d
> wrote:
>> On 11/11/2019 3:26 AM, Nicholas Wilson wrote:
>>> The breaking changes are massive and not well argued for.
>>> The suggested workaround of
>>> 1) a = a ~ b;
>>> in place of
>>> 2) a ~= b;
>>> is functional identical, thus any issues present in 2 are also present
>>> in 1.
>> The point is making it obvious that the GC is being used, i.e. it is
>> intentional behavior.
> Both ~ and ~= use the GC, and it should be obvious that they do, since they
> can't work if they don't. Using ~ isn't any clearer than ~=, and ~ has worse
> performance when a dynamic array is able to grow in-place.

Yes. And the more I see this example, the worse job it does as an 
example of why this DIP is needed.

In order for the DIP to guarantee the pointer of a slice is still the 
pointer to memory to be freed, you have to *disable assignment*. Do we 
want to do that too?

It also must disable popFront, or really any operation except for opIndex.

Here's another example of an error like the item in the DIP, which is 
totally possible even with the DIP:

@nogc: // just to emphasize
int[] slice = (cast(int*)malloc(10 * int.sizeof))[0 .. 10];
   int[1] arr;
   slice = arr[];
else version(alsoBad)
   slice = slice [1 .. $]; // slice doesn't grow!
free(slice.ptr); // Oops;


More information about the Digitalmars-d mailing list