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

Nim's new garbage collector was designed with embedded systems in mind [1]. It uses non-atomic/non-locking reference counting combined with C++11 move semantics. The usage of move semantics enables both performance increases and a method to ensure memory is only "owned" by one thread (which enables non-atomic reference counting). Theres optional cycle collection support but I prefer to keep embedded code acyclical.

On your second point you can use Nim's effect system to ensure no allocations occur in a given function or its callees. Currently no one has done this, and might be tricky with the reference counting, but not too difficult either.

I used Nim with ARC for a latency sensitive embedded project. To avoid allocation on the tight reading loop I pre-allocated the values needed, or made them global variables. A few extra integer ops didn't matter, but allocation is sloooow. However, I'd eventually like to add allocation tracking to the effect system. Rather, make the existing effects more granular for this purpose.

1: https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc...



FYI there's also this newer document on memory management options: https://nim-lang.org/docs/gc.html




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

Search: