<div dir="ltr"><div><div>This seem to work <a href="https://gist.github.com/Bad-ptr/3ea0d6d65ae18b5b68c6cb15a96fef8e">https://gist.github.com/Bad-ptr/3ea0d6d65ae18b5b68c6cb15a96fef8e</a> .</div></div><div><br></div><div>However the documentation says that:</div><div>> All terms of type ERL_NIF_TERM belong to an environment of type ErlNifEnv. The lifetime of a term is controlled by the lifetime of its environment object.<br></div><div><br></div><div>> Variables of type ERL_NIF_TERM can refer to any Erlang term. This is an opaque type and values of it can only by used either as arguments to API functions or as return values from NIFs. All ERL_NIF_TERM's belong to an environment (ErlNifEnv). A term can not be destructed individually, it is valid until its environment is destructed.<br></div><div><br></div><div>> The environment is only valid in the thread where it was supplied as argument until the NIF returns. It is thus useless and dangerous to store pointers to process bound environments between NIF calls.<br></div><div><br></div><div>So, it is not clear to me is it safe to store an ERL_NIF_TERM(in a form as it passed to a NIF function) in a datastructure created by a NIF function? And does the GC aware that this terms must not be collected ? Etc.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 9 July 2016 at 21:59, Steve Vinoski <span dir="ltr"><<a href="mailto:vinoski@ieee.org" target="_blank">vinoski@ieee.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sat, Jul 9, 2016 at 1:54 PM, Constantin Kulikov <span dir="ltr"><<a href="mailto:zxnotdead@gmail.com" target="_blank">zxnotdead@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">If I want to add a new datastructure to erlang(my local fork of the erlang-otp from github), what should I do? Yes, I mean a C-level module realization.<div><br></div><div>Let's say I want to add a double linked list(just for simplicity) module with an interface like that:</div><div>dlist:new() -> ?some king of reference to a list?</div><div>dlist:push(item) -> ?reference to a list?</div><div>dlist:pop() -> {item, ?reference to a list?}</div><div>etc...</div><div><br></div><div><div>Is it possible at all? Has anyone ever tried to do something like this?</div></div><div>What definitions to what files should I add? How must I allocate my data structure? How must I reference items in it?<br></div><div>Can someone point me to source locations where erlang's list/ets table/tuple operations(creating a new, storing a reference to objects) defined?</div></div></blockquote><div><br></div></div></div><div>See</div><div><br></div><div><a href="http://erlang.org/doc/tutorial/nif.html" target="_blank">http://erlang.org/doc/tutorial/nif.html</a><br></div><div><a href="http://erlang.org/doc/man/erl_nif.html" target="_blank">http://erlang.org/doc/man/erl_nif.html</a></div><span class="HOEnZb"><font color="#888888"><div><br></div><div>--steve</div></font></span></div></div></div>
</blockquote></div><br></div>