Do array literals still always allocate?

Nicholas Wilson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 14 05:16:15 PDT 2017


On Sunday, 14 May 2017 at 12:02:03 UTC, Eugene Wissner wrote:
> On Sunday, 14 May 2017 at 11:45:12 UTC, ag0aep6g wrote:
>> On 05/14/2017 01:40 PM, Nicholas Wilson wrote:
>>> dynamic array literals is what I meant.
>>
>> I don't follow. Can you give an example in code?
>
> void main()
> {
>     ubyte[] arr = [ 1, 2, 3, 4, 5 ];
>
>     assert(arr == [ 1, 2, 3, 4, 5 ]);
> }
>
> Both, assignment and comparison, allocate.

LDC is able to promote those to alloca, not sure about DMD or its 
interaction with @nogc.
see 
https://github.com/ldc-developers/ldc/blob/master/gen/passes/GarbageCollect2Stack.cpp#L832 for the details.


More information about the Digitalmars-d-learn mailing list