nif resource lifetime

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

nif resource lifetime

Benoit Chesneau-2
How do you manage the lifetime of a nif resource when it has been created and can be used by one another?

1) I an object O1 and expose it as a resource R1
2) I’m created R2 that need the object O1exposed by R1 by passing R1 as an argument to the nif function used to create R2

I would like to make sure that the object is not preemptively killed or garbaged collected. How would you do it? Any feedback is welcome :)

- benoît
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: nif resource lifetime

Daniel Goertzen-3
When forming R2 you would call enif_keep_resource(&O1), and the R2 destructor would enif_release_resource(&O1).  This assures O1 sticks around while R2 is alive even if R1 dies.

I'm assuming R2 refers to an O2 which in turn is referring to an O1.


On Tue, Sep 5, 2017 at 11:58 AM Benoit Chesneau <[hidden email]> wrote:
How do you manage the lifetime of a nif resource when it has been created and can be used by one another?

1) I an object O1 and expose it as a resource R1
2) I’m created R2 that need the object O1exposed by R1 by passing R1 as an argument to the nif function used to create R2

I would like to make sure that the object is not preemptively killed or garbaged collected. How would you do it? Any feedback is welcome :)

- benoît
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions