In embedded environments, often you just can’t afford a garbage collector.
Note
Of course, if you use the current SDK without the GC, it will just leak through every hole That said, since there are many people interested in an SDK that doesn’t rely on the GC, we’ll do something about it. I’m thinking maybe version(!gc) {} blocks would be useful here.
Step 1: use -gc=off to avoid linking with libgc
If you want to compile without the gc, use the -nogc compiler flag, e.g.
That way, it won’t try to link with libgc.
Note
Remember, to see what commands ooc launches, use the -v compiler option
Step 2: change the definitions of gc_[malloc, realloc, free] in sdk/ooclib.ooc
Here’s the part of the sdk/ooclib.ooc file with memory allocation related definitions:
gc_malloc: extern(malloc) func (size: SizeT) -> Pointer
gc_malloc_atomic: extern(malloc) func (size: SizeT) -> Pointer
gc_realloc: extern(realloc) func (ptr: Pointer, size: SizeT) -> Pointer
gc_calloc: extern(calloc) func (nmemb: SizeT, size: SizeT) -> Pointer
As you can see, aliasing gc_malloc to malloc etc. is very easy and has no runtime cost (e.g. occurences of gc_malloc are just replaced with malloc)
Note
To use a custom sdk, specify its path by setting the OOC_SDK environment variable before launching ooc.
Step 3: PROFIT!
If you’re disabling the GC just to manual memory management, you may want to check out alternative malloc implementations, such as TCMalloc