Do array literals still always allocate?
Nicholas Wilson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 14 01:42:16 PDT 2017
On Sunday, 14 May 2017 at 01:15:03 UTC, Lewis wrote:
> On Saturday, 13 May 2017 at 19:22:09 UTC, Steven Schveighoffer
> wrote:
>> It's just out of date. Can't remember the version, but this
>> did use to allocate. It doesn't any more. But only for this
>> case. In most cases it does allocate.
>
> Okay cool, that's good to hear. For reference the most recent
> place I remember seeing this was
> http://stackoverflow.com/questions/6751575/how-to-initialise-static-arrays-in-d-without-a-gc-allocation (although I've definitely seen others in the past). I'll add an answer to the SO question to clarify that this is no longer an issue.
>
> Thanks all!
It may allocate if it is returned. I think it elided for one
caller because it constructs into the callers stack frame but
only if the length of all return path are the same length. For 2D
or higher it always allocates, i think.
More information about the Digitalmars-d-learn
mailing list