Using a non-thread safe library in a NIF

Thanks for the confirmation, I’ve never written multi-threading code before, so that was very useful. Looks like the library definitely belongs outside of BEAM.

More information about nifs and memory

Looks like the shared library will allocate memory from the calling OS process. For it to allocate memory on the calling erlang process, there would also need to be a mechanism for garbage collection to work.

The nif interface provides mechanisms for memory and thread management:

Previous experimentation with sqlite and memory management: