[erlang-questions] Managing object lifetimes from NIF

Gregory Haskins <>
Wed May 25 22:51:44 CEST 2011


On 5/25/11 4:46 PM, Gregory Haskins wrote:
> Hi All,
> 
> Is it possible to safely retain references to objects like an
> ERL_NIF_TERM inside a NIF resource?
> 
> For instance, can I have
> 
> struct myresource {
> 	ErlNifPid *pid;
> 	ERL_NIF_TERM *term;
> };
> 
> and allocate this structure with enif_alloc_resource in such a way that
> I can ensure (either implicitly or explictly) that pid/term are properly
> reference counted till at least the dtor is called on my resource?
> 
> Thanks!
> -Greg
> 
> 

NM, I think I figured it out.

I think the answer is that I want to create a custom ErlNifEnv created
by enif_alloc_env() and use that for the resource's contained objects.

Thanks all,
-Greg

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 267 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110525/ac9ba977/attachment.bin>


More information about the erlang-questions mailing list