Scope storage class

Russell Lewis webmaster at villagersonline.com
Mon Dec 1 09:26:31 PST 2008


Robert Jacques wrote:
> Just as a point of reference (in D1)
> scope Object a = new Object(); // Stack Allocated
> scope Object b;
> b = new Object(); // Heap Allocated
> 
> So there may be some merit to scope int b() { .. } vs scope int b(); b = 
> {...}

I can't find any spec on exactly how scope works, but this makes 100% 
sense to me.  Let me explain the way that I think scope 
does/might/should work:

The thing to remember is that "scope" is *not* transitive.  Scope limits 
the most shallow reference, *not* not anything deeper.  It is perfectly 
valid to have a scope pointer to a non-scope thing.  The point of scope 
is to enforce that the pointer cannot escape; it does not say anything 
about whether the pointed-to object escapes or not.

The point then, is that you can create a non-scope object, and assign it 
to a scope pointer.  When you do something like:

BEGIN CODE
	scope <type> a;
	a = <allocate thing>;
END CODE

...you are doing exactly that.

(At least, that's how I think it ought to work.)


More information about the Digitalmars-d-announce mailing list