Proposal for design of 'scope' (Was: Re: Opportunities for D)
Jacob Carlborg via Digitalmars-d
digitalmars-d at puremagic.com
Tue Jul 15 07:41:00 PDT 2014
On 15/07/14 14:47, Adam D. Ruppe wrote:
> 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.
Yes, I agree.
> 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.
If a class is allocated on the stack, its destructor will be called (at
least according to the spec). If you declare a class "scope" you know it
will always be allocated on the stack and can take advantage of that.
Even if all classes are "scope" compatible some might _only_ be
compatible with "scope".
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list