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

jmh530 john.michael.hall at gmail.com
Mon Nov 11 14:34:16 UTC 2019


On Monday, 11 November 2019 at 13:26:56 UTC, Adam D. Ruppe wrote:
> [snip]
>
> It should probably just be
>
> int[] slice = (cast(int*)malloc(10 * int.sizeof))[0 .. 10];
>
>
> Since the type certainly should be int[], and it will compile.

Ah, thanks.

So I could probably re-write this as

```
     int* data = cast(int*)malloc(10 * int.sizeof);
     int[] slice = data[0 .. 10];
```

So maybe the issue is with being able to slice arbitrary 
pointers? I don't know...

It all seems tied in to the ability to conflate a malloc'ed slice 
with a GC'ed slice. If anything, I don't think it should be easy 
to do this.


More information about the Digitalmars-d mailing list