I am currently playing around with the shared heap which I want to use for some callback procedures that are called by different threads. The idea is that all callback procedures should use the same logger object for logging and I thought that using the logger on the shared heap is better than declaring the logger as a global threadvar because of concurrent file access.
I used the below code as a test and as I am not a Nim or C/C++ expert I wonder if it will really move/copy the logger object to the shared heap. Is there maybe a better approach?
import logging
var plogger: ptr RollingFileLogger
proc callbackTest() =
var logger = newRollingFileLogger()
plogger = cast[ptr RollingFileLogger](allocShared0(sizeOf(logger)))
plogger[] = logger
callbackTest()
plogger[].log(lvlInfo, "Test")
deallocShared(plogger)