3 ms·
Thank you. > 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 libr
by guggle 7y ago
Thank you.
> 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").
- joshbaptiste 7y agoNim's GC is optional
- Touche 7y agoHow can it be optional if there is lots of code that assumes you are using GC? For example, as far as I can tell the stdlib doesn't do its own allocations. Does this mean you can't use the stdlib with GC disabled? Or am I missing something here?
- qmmmur 7y agoA friend of mine wrote a DSL for audio using Nim with GC off. https://github.com/vitreo12/omni 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.
- alehander42 7y agooverally if you write an os you need to write your malloc/free .. and then you should be able (i think..) to use many of the gc-s anyway and more of stdlib. 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)
- alehander42 7y agoyou're right, it is confusing, but it is optional: some toy kernels already work in nim , and with latest work on memory, you should be able to use most of the language for kernel development ! not the perfect language for that yet though, but i hope we should see more nim os examples
- Touche 7y agoAre you saying that the GC is optional? If you don't use it how do you allocate/free memory?
- guggle 7y agoDidn't test this but some clues: https://nim-lang.org/docs/gc.html https://nim-lang.org/docs/gc.html Then I guess you would use new/dealloc
- guggle 7y agomore here: https://nim-lang.org/araq/destructors.html https://nim-lang.org/araq/destructors.html
- alehander42 7y agooverally i think for small os-es you can write easily a micro libc core in C or even in Nim where you define malloc/free etc and just use them directly as in C and zig. otherwise you should be able to use something like destructors eventually
- mratsim 7y agoYou call malloc/free, or if working with GPU cudaMalloc/free. You can write your own memory pool or object pools, you can use destructors, and even implement your own reference counting scheme. 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 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/datatypes/pledges.nim#L178-L212 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/ 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.
- 7y ago