Why are immutable array literals heap allocated?

a11e99z black80 at bk.ru
Thu Jul 4 11:52:42 UTC 2019


On Thursday, 4 July 2019 at 10:56:50 UTC, Nick Treleaven wrote:
> immutable(int[]) f() @nogc {
>     return [1,2];
> }
>
> onlineapp.d(2): Error: array literal in `@nogc` function 
> `onlineapp.f` may cause a GC allocation
>

specify the size of the static array:
immutable(int[ 2 /*HERE*/ ]) f() @nogc { return [1,2]; }


More information about the Digitalmars-d-learn mailing list