How to get nogc to work with manual memory allocation

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 4 23:43:54 PDT 2014


On Sunday, 24 August 2014 at 09:29:53 UTC, Jacob Carlborg wrote:
> On 2014-08-24 10:03, Bienlein wrote:
>
>> I have omitted the code for the TestClass class to save space. 
>> Problem
>> is that the compiler outputs this:
>>
>> Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' 
>> cannot call
>> non- at nogc function 'core.exception.onOutOfMemoryError'
>> Error: @nogc function 'main.nogcNew!(TestClass, ).nogcNew' 
>> cannot call
>> non- at nogc function 'std.conv.emplace!(TestClass, ).emplace'
>> Error: @nogc function 'main.nogcDel!(TestClass).nogcDel' 
>> cannot call
>> non- at nogc function 'object.destroy!(TestClass).destroy'
>>
>> Is there a way to get around this?
>
> @nogc is a very new attribute. The runtime and standard library 
> have not been properly annotated with this attribute yet.
>
> As a workaround you could try copy implementation of these 
> functions to you're own code and annotate them as appropriate.

The real issue here is actually the *language*. Exceptions and 
Errors are GC allocated, so if you try to "check" your no-GC 
allocation, you'll use the GC...

A possible workaround is to preemptively static allocate the 
Error. However, this can cause issues if you chain Errors, or 
re-enter your function while throwing.


More information about the Digitalmars-d-learn mailing list