DIP1000: Scoped Pointers

Dicebot via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Wed Aug 17 03:52:34 PDT 2016


On 08/17/2016 10:53 AM, Mike wrote:
> On Wednesday, 17 August 2016 at 07:17:24 UTC, Rory McGuire wrote:
>>
>>>   If DIP1000 is implemented, it will change that behavior, so the
>>> allocation will instead be on the GC heap, but the compiler will do some
>>> flow-control analysis to prevent escaping references.  Is that right?
>>>
>>> Mike
>>>
>>
>> Not correct, the class would still be on the stack so we can have
>> reference semantics during assignment etc, but the instance is on the
>> stack so its faster and the function the code is inside can optionally
>> be nogc.
>>
>> DIP1000 will just make the compiler check that a stack instance does
>> not escape its scope (though it doesn't cover all cases).
>>
>> struct Astruct {} // - on stack by default
>> class Aclass  {} // - on heap by default
>> void main() {
>>     Astruct a = new Astruct; // override, now Astruct is on the heap
>> (because of "new")
>>     Aclass c = new Aclass; // on the heap as per-usual
>>     scope Aclass c1 = new Aclass; // override, now class is on the stack
>> (most obvious use: to make all references use the same instance)
>> }
> 
> Got it!  Thank you!  But it still appears that what's illustrated on the
> deprecations page is not being deprecated.
> 
> Mike

Yes, it will have to be updated - but I didn't want to adjust it before
DIP1000 spec is finalized. Rationale that was driving deprecation of
scope storage class is becoming obsolete with DIP1000 implemented but
not before.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-announce/attachments/20160817/e60f757d/attachment.sig>


More information about the Digitalmars-d-announce mailing list