Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

is this production ready? last time I checked GC for c and c++ and I don't think c and c++ are really GC-friendly by design. After nim's transpiling, is c/c++ using those data structures and functions somehow to manage resources(similar to RAII) but not really acting as a GC in c/c++?


Nim offers a choice of several GCs:

https://nim-lang.org/1.6.0/gc.html

for upcoming v2: https://nim-lang.org/docs/mm.html

Note that beginning with v1.6.2 it's specified with `--mm:[choice]` instead of `--gc:[choice]`, though the latter still works.

And beginning with v2, the default GC will be orc, while to date it's refc. That's an important change and has involved a lot of hard work by maintainers and contributors leading up to the release of v2.0.0.

See also the user guide for Nim's compiler:

https://nim-lang.org/docs/nimc.html


C and C++ both have very popular GC libraries which fulfill much the same purpose and even have the same design (the optional Boehm GC, for example). Those are likely good examples to look at to see how managed memory might be invoked by the Nim compiler. Alternatively, if you're using reference counting, that's simply C++'s preferred style (std::unique_ptr), as you already said. I can't speak to whether Nim's compiled code is using std::unique_ptr or something else.


Nim treats C/C++ as portable assembly, so you should think more in terms of compilation than "transpilation". While it can use C gc's like Boehm, it can also use the new ORC that benefits from optional lifetime annotations like `lent` and `sink` to optimize out reference counting, making it more similar to Rust or C++ smart pointers for example.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: