> I don't know Nim, but I believe it has a garbage collector so it could be tricky to use for kernel programming.
You're right. Still good for libraries though (or apps, but that may be outside of "system").
> I don't know Nim, but I believe it has a garbage collector so it could be tricky to use for kernel programming.
You're right. Still good for libraries though (or apps, but that may be outside of "system").
Then I guess you would use new/dealloc
otherwise you should be able to use something like destructors eventually
This is what I use for my own multithreading runtime in Nim and the memory subsystem makes it faster and more robust than any runtime (including OpenMP and Intel TBB) that I've been benchmarking against, see memory subsystem details here: https://github.com/mratsim/weave/tree/master/weave/memory
Example of atomic refcounting in this PR here: https://github.com/mratsim/weave/blob/025387510/weave/dataty...
Also one important thing, Nim current GC is based on TLSF (http://www.gii.upv.es/tlsf/) which is a memory reclamation scheme for real-time system, it provides provably bounded O(1) allocations. You can tune Nim GC with max-pauses for latency critical applications.
Also, the new ARC memory manager replaces GC and can run in a kernel.
As soon as you use sequences or strings or async you depend on the GC.
You can however compile with gc:destructors or gc:arc so that those are managed by RAII.
I meant that new ARC GC, that will replace the current one, can be used for the kernel.
It's still a GC, technically, but, quoting Araq on ARC:
Nim is getting the "one GC to rule them all". However calling it a GC doesn't do it justice, it's plain old reference counting with optimizations thanks to move semantics.
https://github.com/vitreo12/omni
I don't know enough to comment but it may be useful to look at things in the wild. This project also heavily relies on calling in C to interface with environments and the SuperCollider scsynth.
But you can also think of Nim as macro-able higher level C and write it like that (but indeed you probably still need this minimal allocation support)