I'm working on a hobby OS, and one thing I'm tackling next is trying to leverage Nim's heap allocator instead of writing my own allocator. I know that in osalloc.nim Nim uses the underlying OS page allocator to allocate/free pages (e.g. mmap/munmap or VirtualAlloc/VirtualFree), and that there's an option nimAllocPagesViaMalloc that, when used, will use malloc instead.
My OS has a capability to allocate and free VM pages, so I don't want to rely on malloc since it over-allocates memory and does the alignment itself. What are my options here? Ideally I'd like to avoid patching the compiler for my own purposes. I thought about providing a posix implementation of mmap/munmap, but it's not clear to me how to ask Nim to use my implementation without claiming that my OS is posix compliant, which it is not.
Oh, interesting. Didn't know about patchFile. Now that I read the docs on nimscript and did some research on the compiler code, I can't seem to get it to work. This is what I have:
# src/kernel/config.nims
patchFile("nim", "osalloc", "../nimpatches/osalloc")
where my patched version is in src/nimpatches/osalloc.nim. It seems to be read by the compiler:
Hint: used config file '[snip]/src/kernel/config.nims' [Conf]
But it's not taking any effect. Is this maybe because osalloc.nim is included instead of imported?
As Araq said it should be "stdlib"
This was for me a learning point on how to use patchFile :
https://github.com/Yardanico/mimalloc_nim/blob/master/src/main.nims