Cannot compare object.opEquals is not nogc

Mark J Twain via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 2 16:08:29 PDT 2016


A hack is to create the gc code you in a function want to call, 
say does the "gc" opEquals. Then cast that function to a nogc 
version by first casting to a void*. This way you can call gc 
code from nogc code, by bypassing the compiler's ability to 
check. It will obviously break your code if you disable the gc 
completely and there are no easily ways to find the hacks(have to 
resort to marking and -vgs).


	@nogc void function() foo;
	void* bar = ()
	{        	
            // Use GC
	};
	
         alias A = @nogc void function();
	foo  = cast(A)bar;

now foo, which points to the GC based bar, but is makred nogc and 
callable in nogc code.

One can probably make a template GC2NoGC that does all this and 
to get completely off the GC, one just has to rework the 
anonymous functions(mark them nogc). So it is somewhat of a clean 
solution as it allows you to separate your gc dependencies in to 
well defined blocks that then can be addressed later when one 
truly wants to get off the GC.





More information about the Digitalmars-d-learn mailing list