[erlang-questions] NIFs Reloading

Sverker Eriksson sverker@REDACTED
Wed Oct 5 14:35:09 CEST 2011


Michael Uvarov wrote:
> Hello,
>
> How to load new version of c-code with NIFs?
>   
There are two ways to do that (in a running system).

* The right way:

Load the new version of your module and let that new Erlang code load 
your new NIF library with erlang:load_nif/2. The callback 'upgrade' will 
then be called in your new library (instead of 'load") and that will 
give you opportunity to transfer state from your old library if you want 
to. The 'unload' callback will later be called in your old NIF library 
before the old version of your module is purged.

The above is the recommended way to upgrade a NIF library in runtime as 
it harmonize with how "normal" module upgrade is done.

* The quick and dirty way:

Just call erlang:load_nif/2 a second time from the same Erlang module 
instance. This will just replace the NIF library while leaving the 
Erlang code in place. The callback 'reload' is called in this case.
This is only recommended during development (as a fast way to load your 
upgraded NIF code) and not as an upgrade procedure for a running 
production system. I actually regret that we supported this feature as 
it can complicate future improvements of the code loading mechanisms in 
the emulator. It is possible that we will retract this reload feature in 
some future release (R15 maybe).

/Sverker, Erlang/OTP Ericsson




More information about the erlang-questions mailing list