Why are immutable array literals heap allocated?

Max Haughton maxhaton at gmail.com
Fri Jul 5 17:13:12 UTC 2019


On Friday, 5 July 2019 at 16:25:10 UTC, Nick Treleaven wrote:
> On Thursday, 4 July 2019 at 11:06:36 UTC, Eugene Wissner wrote:
>>     static immutable arr = [1, 2];
>>
>> You have to spell it out that the data is static.
>
> Yes, I was wondering why the compiler doesn't statically 
> allocate it automatically as an optimization.

LDC might be able to optimize it away but by default its heap 
allocated, I imagine for thread safety


More information about the Digitalmars-d-learn mailing list