<div dir="auto">Modifying the way how garbage collect algorithm calculates the root set will do what you want. Now the trick is that GC runs per process and nifs are organized independently. There must be a way for a process to know which nif holds something from its heap.</div><div class="gmail_extra"><br><div class="gmail_quote">On Feb 8, 2017 05:22, "Jean Rougé" <<a href="mailto:rouge.j@gmail.com">rouge.j@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">Hi,</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">If NIFs want to keep an erlang term around, they currently have to copy them to their own, process-independent environment, using enif_make_copy.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">That can be a pretty big performance issue if dabbling with big terms: imagine for example a NIF storing a complicated data structure, e.g. a gb_tree; now say we want to keep adding/deleting items from that gb_tree in our erlang code: we now have to copy the entire thing back and forth.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">How hard/conceivable would it be to give NIFs a way to keep a pointer to an erlang term that they could pass back and forth with the process' environments without having to copy everything?</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I imagine that would mean that it would be the NIF's programmer responsibility to:</div><div style="font-size:12.8px"><ul><li style="margin-left:15px">ensure that they never keep a pointer to an erlang term that's no longer referenced in erlang land (and hence is going to get garbage collected)</li><li style="margin-left:15px">ensure thread-safety</li></ul>But the erlang VM would still have to somehow let the NIF know when an erlang term it has a pointer to has been moved somewhere else.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Is that something that could maybe, in theory, be possible to add to the current VM?</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Thanks a lot,</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Jean</div></div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>