Small @nogc experience report

Eugene Wissner belka at caraus.de
Fri Sep 7 17:35:12 UTC 2018


On Friday, 7 September 2018 at 17:01:09 UTC, Meta wrote:
> Semi-unrelated, but I think you should open a bug for this one. 
> I remember Andrei stating before that every function in 
> std.algorithm except for LevehnsteinDistance(?) is @nogc, so he 
> either missed topNCopy or the gc-ness of the function has 
> changed sometime between ~2015 and now.

It was never true. Here is another example:

import std.algorithm;

void main() @nogc
{
     int[4] a, b;

     fill(a[], b[]);
}

The funny thing is that fill() doesn't always allocate, but only 
if the element to fill with, is an array. fill() uses enforce() 
which allocates and throws. Other algorithms (e.g. equal) have 
special handling for character arrays and throw if they get wrong 
unicode or use some auto-decoding functions that aren't @nogc.


More information about the Digitalmars-d mailing list