@nogc, exceptions, generic containers... Issues.

Jakob Ovrum via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 9 02:04:34 PDT 2014


On Monday, 8 September 2014 at 15:55:53 UTC, monarch_dodra wrote:
> A particularly relevant example of this issue is `RefCounted`: 
> This struct uses malloc to ref count an object, give a 
> deterministic life cycle, and avoid the GC. Yet, since malloc 
> can fail, it does this:
> _store = cast(Impl*) enforce(malloc(Impl.sizeof));
> Can you see the issue? This object which specifically avoids 
> using the GC, end up NOT being @nogc.

Although it's tangential to the issue at large, this particular 
code is wrong anyway. It should be using `onOutOfMemoryError` 
(which should be @nogc), otherwise the allocation of the 
exception is likely to fail just as `malloc` did.


More information about the Digitalmars-d mailing list