DIP 1008 Preliminary Review Round 1

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Fri May 19 14:24:51 PDT 2017


On Friday, 19 May 2017 at 19:46:07 UTC, nkm1 wrote:
> I like this proposal... But it looks like people are concerned 
> about 'new' becoming contextual keyword (that in some contexts 
> it allocates with GC and in others it does something else)

It *already* does that. `new` can be overloaded and modified with 
`scope`.

http://dlang.org/spec/expression.html

"NewExpressions are used to allocate memory on the garbage 
collected heap (default) or using a class or struct specific 
allocator. "

"If a NewExpression is used as an initializer for a function 
local variable with scope storage class, and the ArgumentList to 
new is empty, then the instance is allocated on the stack rather 
than the heap or using the class specific allocator. "


I also believe the compiler *should* be free to optimize it to a 
different allocation scheme if it proves it safely can.


More information about the Digitalmars-d mailing list