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:
- enif_thread_create
-
enif_alloc
Erlang specific malloc that gives a shared memory region. - enif_mutex_create
-
erl_nif_open_resource_type
This one also appears to be shared memory.
c - Erlang NIF from single process storing structs in memory - Stack Overflow
Previous experimentation with sqlite and memory management:
-
Ecto_sqlite3 - an Ecto3 SQLite3 adapter - #38 by tj0
Looks like the memory is not shown in observer either, but remains resident, but not on eheap_alloc.