https://github.com/nim-lang/Nim/blob/devel/lib/system/gc_regions.nim
There is not really any documentation - you basically create a memory region and then use the provided templates to allocate memory using the region. The region, along with all memory allocated to it, can be destroyed at once.
Thanks for the reply.
So to use regions, do you have to declare regions manually or does the compiler take care of it automatically when compiled with --gc:regions? I ask this because even using stdlib, when compiled with --gc:regions the compiler doesn't throw any errors and everything works as expected. But I'm not sure if memory is freed properly.
You check it's code to have an idea how it is working
https://github.com/nim-lang/Nim/blob/devel/lib/system/gc_regions.nim
@emg - as @cdome mentioned - your best bet is to look at the code since the feature isn't really documented.
You can explicitly free the region, however I have a feeling the GC will collect it anyway regardless.
Not sure what you're trying to achieve with regions - I haven't seen them used anywhere practically.
Hi,
I'm trying to see if regions is appropriate for FFI interfaces. I need to allocate some sequences and pass it to FFI functions and later, dealloc them. Currently, GC_Ref and GC_Unref is an option, but still a bit unintuitive and have to be very careful for every allocation. With regions, theoretically I can allocate a bunch of stuff from the same region and later free all of it in one call.