Why avoid calling enif_make_atom?

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

Why avoid calling enif_make_atom?

Roger Lipscombe-2
All of the NIF-using Erlang projects I've found seem to allocate their
atoms during load. Some examples:

- jiffy: https://github.com/davisp/jiffy/blob/master/c_src/jiffy.c
- re2: https://github.com/tuncer/re2/blob/master/c_src/re2_nif.cpp#L180

I also found some skeleton NIF code, at
https://github.com/davisp/nif-examples/blob/master/apps/termsend/c_src/termsend.c#L4,
that checks enif_make_existing_atom first.

I guess my question is:

What's the harm in calling enif_make_atom whenever I need an atom
term? Does it leak atoms?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Why avoid calling enif_make_atom?

Loïc Hoguin-3
An example from OTP itself:
https://github.com/erlang/otp/blob/master/erts/emulator/nifs/common/erl_tracer_nif.c#L54

I think it's more an optimization. Call the function only once on load
and then use the static variables directly.

On 02/23/2017 12:04 PM, Roger Lipscombe wrote:

> All of the NIF-using Erlang projects I've found seem to allocate their
> atoms during load. Some examples:
>
> - jiffy: https://github.com/davisp/jiffy/blob/master/c_src/jiffy.c
> - re2: https://github.com/tuncer/re2/blob/master/c_src/re2_nif.cpp#L180
>
> I also found some skeleton NIF code, at
> https://github.com/davisp/nif-examples/blob/master/apps/termsend/c_src/termsend.c#L4,
> that checks enif_make_existing_atom first.
>
> I guess my question is:
>
> What's the harm in calling enif_make_atom whenever I need an atom
> term? Does it leak atoms?
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

--
Loïc Hoguin
https://ninenines.eu
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions