Proposal for design of 'scope' (Was: Re: Opportunities for D)
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 15 05:47:07 PDT 2014
On Tuesday, 15 July 2014 at 06:42:20 UTC, Jacob Carlborg wrote:
> 1. Allocate classes on the stack: "scope bar = new Bar()"
> 4. Scope parameters. This is the part that is unclear what is
> means/is supposed to mean in the current language
These are actually the same thing: if something is stack
allocated, it must not allow the reference to escape to remain
memory safe... and if the reference is not allowed to escape,
stack allocating the object becomes an obvious automatic
optimization.
People keep calling them deprecated but they really aren't - the
escape analysis to make it memory safe just isn't implemented.
> 2. Forcing classes to be allocated on the stack: "scope class
> Bar {}"
I think this is the same thing too, just on the class instead of
the object, but I wouldn't really defend this feature, even if
implemented correctly, since ALL classes really ought to be scope
compatible if possible to let the user decide on their lifetime.
More information about the Digitalmars-d
mailing list