On Tuesday, 14 April 2015 at 07:06:24 UTC, John Colvin wrote:
On Monday, 13 April 2015 at 19:45:37 UTC, deadalnix wrote:
On Monday, 13 April 2015 at 17:04:51 UTC, John Colvin wrote:
Eww.

auto arr = new int[3];

Also, I think he's referring to something slightly different.

IMO, that shouldn't be too difficult to promote that on stack if the reference do not escape in most cases.

The problem is that the size isn't necessarily known. I guess the compiler could put in a branch, but at that point you'd probably want to give the programmer control and have a way of making it explicit.

The branch being way cheaper than an allocation anyway, and likely to be very predictable, I'd go for it anyway.

You can always add a compiler flag --max-stack-promotion-size=XXX to configure the thing, with a sensible default.

This approach is far preferable as the compiler can do it AFTER inlining take place, so can promote stuff on the stack that don't like you'd be able to looking at the code.

Reply via email to