scoped allocations

Namespace rswhite4 at googlemail.com
Wed Nov 27 02:14:30 PST 2013


On Wednesday, 27 November 2013 at 08:55:01 UTC, Andrea Fontana 
wrote:
> On Tuesday, 26 November 2013 at 23:33:59 UTC, Namespace wrote:
>>
>> Temp!int arr = Temp!int(512); /// arr is destroyed at the end 
>> of the scope
>> ----
>>
>> But that does not look very nice (especially because Temp!int 
>> does not indicate that it holds an array).
>
> If you call it something other than "Temp" maybe it sounds 
> better.
>
> auto arr = ScopedArray!int(512);
>
> Makes sense for me.

It was just an example, but you're right. But even auto arr = 
ScopedArray!int(512); doesn't look very nice. Some syntax sugar 
like e.g. scope int[] arr = new int[512]; would be much nicer + 
more intuitive.

And with some of the other examples, like the DIP 46 variant, D 
could keep his promise to work even without a GC.
Currently you can disable it, but then you have very little 
benefit of the most basic things, such as strings, arrays, etc. 
With an exchangeable GC this would be different.


More information about the Digitalmars-d mailing list