DIP60: @nogc attribute

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 17 08:49:43 PDT 2014


On Thursday, 17 April 2014 at 15:39:38 UTC, Ola Fosheim Grøstad 
wrote:
> On Thursday, 17 April 2014 at 15:02:27 UTC, Dicebot wrote:
>> void foo(OutputRange buffer)
>> {
>>    buffer.put(42);
>> }
>>
>> `foo` can't be @nogc here if OutputRange uses GC as backing 
>> allocator. However I'd really like to use it to verify that no
>
> Can't you write foo as a template? Then if "buffer" is a ring 
> buffer the memory might be allocated by GC, which is ok if 
> put() does not call the GC and is marked as such.

put() may call GC to grow the buffer, this is the very point. 
What is desired is to check if anything _else_ does call GC, thus 
the "weak @nogc" parallel.

> Where this falls apart is when you introduce a compacting GC 
> and the @nogc code is run in a real time priority thread. Then 
> you need both @nogc_function_calls and @nogc_memory .

True hard real-time is always special, I am speaking about 
"softer" but still performance-demanding code (like one that is 
used in Sociomantic).

> Of course, resorting to templates requires some thinking-ahead, 
> and makes reuse more difficult.

I don't see how templates can help here right now.

> You'll probably end up with the @nogc crowd creating their own 
> NoGCOutputRange… :-P
>
> Ola.



More information about the Digitalmars-d mailing list