[erlang-questions] weak resource reference possible in nif ?
Fri Nov 10 11:27:01 CET 2017
I just thought of a dirty hack that might work; serialize the resource
on creation with enif_term_to_binary and store *that* in your internal
list instead of the resource, then send the result of
enif_binary_to_term in each notification.
The resource won't be kept alive any longer than needed (As the binary
won't keep any references to it), and it won't crash if the resource
has been deallocated as enif_binary_to_term will recognize it as such
and return a stale resource.
It will only work on OTP 20 or later though.
On tor, 2017-11-09 at 11:06 +0800, Skype Xu wrote:
> We don't want to get a new resource term every time when we got a
> we want to simply use erlang pattern matching without another
> to retrieve
> actual data in the resource and matching against the data, if we do
> this, a programmer
> can keep the data around for later matching, and may forget to keep
> resource, then
> what's the reason to use erlang resource? we would give up.
More information about the erlang-questions