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

Andrea Fontana nospam at example.com
Tue Nov 12 11:25:06 UTC 2019


On Monday, 11 November 2019 at 22:40:44 UTC, Jonathan M Davis 
wrote:
> On Monday, November 11, 2019 2:41:14 PM MST Walter Bright via 
> Digitalmars-d wrote:
> It should be clear to anyone seriously using dynamic arrays that
>
> int[] slice = cast(int*)malloc(10 * int.sizeof)[0 .. 10];
> slice ~= 1;
> free(slice.ptr); // Oops!
>
> is a problem. It's a given that appending can cause a 
> reallocation. But even if appending weren't allowed, you could 
> still have something like
>
> int[] slice = cast(int*)malloc(10 * int.sizeof)[0 .. 10];
> slice = slice[1 .. $];
> free(slice.ptr); // Oops!
>
> and have problems, because the dynamic array isn't slicing the 
> beginning of that block of memory anymore.

+1
It was my first thought



More information about the Digitalmars-d mailing list