[erlang-questions] Is there anyway to share NIF resource type among NIF modules?

Dmytro Lytovchenko <>
Tue Jan 8 14:20:10 CET 2019


The reasonable way would be to use a ref-counted pointer to struct which
will be shared by both NIF modules. I believe it must also be allocated
somewhere in VM memory in case both NIF modules get unloaded. As C is not
particularly famous for its smart refc pointers, you will have to find a
library or do it yourself, and hook the refc check onto both NIF resource
free functions.

On Tue, 8 Jan 2019 at 14:11, Lukas Larsson <> wrote:

> Hello,
>
> On Thu, Jan 3, 2019 at 2:53 PM Wu Ray <> wrote:
>
>> I have a C struct, as a NIF resource type, and want it to be shared
>> between several NIF modules, is it possible?
>>
>
> As far as I know it is not possible.
>
> Lukas
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190108/76b12916/attachment.html>


More information about the erlang-questions mailing list