Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nim and memory management

Tags:

nim-lang

I keep reading that Nim's memory management is optional, but documenttion seems to be thin on this, the only resources I have found relate mostly to FFI to C, and https://nim-lang.org/docs/gc.html

Is it possible to take control of Nim's memory management short of writing a new GC? Any good resources?

like image 318
SourceSimian Avatar asked Jun 28 '19 18:06

SourceSimian


People also ask

Does Nim have GC?

Nim has 5 default GC methods and the upcoming automated reference counting.

What is memory management in IOS Swift?

Swift uses Automatic Reference Counting (ARC) to track and manage your app's memory usage. In most cases, this means that memory management “just works” in Swift, and you don't need to think about memory management yourself.

Does Nim have pointers?

As briefly mentioned above, there are two types of pointers in Nim: ptr T for untraced references, aka pointers.


1 Answers

The only thing you can do to take control over the GC are listed on the docs page you listed. You can control when, and for how long the GC will run. The second option is to completely disable the GC, which allows you to manually manage memory in a more C like fashion with explicit allocations and frees. The third option, which is still very experimental, is called "newruntime" and is outlined here: https://nim-lang.org/araq/ownedrefs.html

like image 133
PMunch Avatar answered Oct 23 '22 05:10

PMunch