<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>On tor, 2019-01-03 at 21:52 +0800, Wu Ray wrote:</div><blockquote type="cite"><div dir="ltr">Hi, guys<div><br></div><div>I have a C struct, as a NIF resource type, and want it to be shared between several NIF modules, is it possible?</div><div><br></div><div>Best Regards</div><div><br></div><div></div></div><pre>
</pre></blockquote><div><br></div><div>There is no offical documented support to use the same resource type from more than one NIF module.</div><div><br></div><div><br></div><div>But if you want to experiment, there are two problems I can think of.</div><div><br></div><div>1. How to get the other NIF modules access to the resource type pointer.</div><div><br></div><div>One way to solve this is to put the resource type in a separate dynamic shared library, dynamically linked by all NIF modules using the resource type.</div><div><br></div><div><br></div><div>2. Prevent usage of an unloaded resource type. </div><div><br></div><div>You must make sure yourself that other modules do not try to use the pointer to an unloaded resource type  (as argument to enif_get_resource or enif_make_resource for example). That will probably lead to VM crash or other unpleasantries.</div><div><br></div><div><div>A resource type will exists as long as the NIF module that called enif_open_resource_type is loaded. If the resource type has a destructor function then the NIF module will not be unloaded until the last resource object is garbage collected.</div><div><br></div><div><br></div><div>/Sverker</div><div><br></div></div><div><br></div><div><br></div><div><br></div></body></html>