[erlang-questions] Can i share nif resource between two nif module?

Steve Vinoski <>
Mon Dec 26 18:44:43 CET 2016


On Mon, Dec 26, 2016 at 4:23 AM, Ildar Khizbulin <>
wrote:

> Hi,
>
> can I transfer resource from one nif to another nif?
>
> For example in first, i write:
>
> capture.c:
>
> static ErlNifResourceType *f_resource;
>
> capture_f() {
>   frame_t* f = enif_alloc_resource(f_resource, sizeof(frame_t));
>   f_term = enif_make_resource_binary(env, f, ....
>   ret = enif_make_tuple2(env, ok_atom, f_term);
>   enif_release_resource(f);
>   return ret;
> }
>
> load() {
>   if(!f_resource)
>     f_resource = enif_open_resource_type(env, NULL, "f_res", flags, NULL);

}
>
> in second
>
> hi.c:
>
> static ErlNifResourceType *f_resource;
>
> process_f() {
>   struct frame_t *f;
>   if (!enif_get_resource(env, argv[0], f_resource, (void **)&f)) { ///<-
> FAIL
>
>
> }
>
> load() {
>   if(!f_resource)
>     f_resource = enif_open_resource_type(env, NULL, "f_res", flags, NULL);
>

Are you including ERL_NIF_RT_TAKEOVER in your flags value here?

--steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161226/c27712a3/attachment.html>


More information about the erlang-questions mailing list