DIP60: @nogc attribute

Brad Anderson via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 18 09:17:10 PDT 2014


On Friday, 18 April 2014 at 14:45:37 UTC, Byron wrote:
> On Thu, 17 Apr 2014 11:55:14 +0000, w0rp wrote:
>
>> I'm not convinced that any automatic memory management scheme 
>> will buy
>> much with real time applications. Generally with real-time 
>> processes,
>> you need to pre-allocate. I think GC could be feasible for a 
>> real-time
>> application if the GC is precise and collections are 
>> scheduled, instead
>> of run randomly. Scoped memory also helps.
>
> I thought the current GC only ran on allocations? If so @nogc 
> is *very*
> useful to enforce critical paths. If we added a @nogcscan on 
> blocks that
> do not contain pointers we maybe able to reduce the collection 
> time, not
> as good as a precise collector.  I would think we can get 
> decent compiler
> support for this (ie.  no refs, pointers, class, dynamic array).

You can actually prevent scanning/collection already without much 
difficulty:

GC.disable();
scope(exit) GC.enable();

I feel like @nogc is most useful in avoiding surprises by 
declaring your assumptions. Problems like how toUpperInPlace 
would still allocate (with gusto) could much more easily be 
recognized and fixed with @nogc available.


More information about the Digitalmars-d mailing list