Automatically using stack allocations instead of GC

Walter Bright newshound2 at digitalmars.com
Mon Oct 23 10:48:37 UTC 2017


On 10/23/2017 2:06 AM, Per Nordlöw wrote:
> Are there any plans (or is it already happening) to make D-compilers 
> automatically use stack allocations when possible in cases like
> 
> int foo()
> {
>      auto x = [1, 2]; // should be allocated on the stack
>      return y = x[0] + x[1];
> }
> 
> where allocations are "small enough" and cannot escape the current scope?

There are no plans at the moment, but it's a good idea that `scope` can make 
possible.

> And how does/should/will this interact with `@nogc`?

If it gets allocated on the stack, then it should be compatible with @nogc.


More information about the Digitalmars-d mailing list