new int[]

Luís Marques luis at luismarques.eu
Wed Jan 10 23:08:28 UTC 2018


On Wednesday, 10 January 2018 at 22:46:30 UTC, ag0aep6g wrote:
> If I understand correctly, the goal is to have the `int[]` 
> itself on the GC heap.

That's correct.

> You can make an `int[][]` with one element, and then take the 
> address of that element:
>
> void main()
> {
>     int[]* x = &[[1, 2, 3]][0];
>     int[]* x2 = [[1, 2, 3]].ptr; /* same */
> }

That's an interesting solution. I'm not sure which one I prefer, 
the wrapper or this one. Still... I feel like the language should 
just allow allocating an array itself on the GC heap :(


More information about the Digitalmars-d-learn mailing list