|
1 | 1 | [[CH-C]] |
2 | | -== Chapter: Interfacing other languages and extending BEAM and ERTS |
| 2 | +== Interfacing Other Languages and Extending BEAM and ERTS |
3 | 3 |
|
4 | 4 | === Introduction |
5 | 5 | Interfacing C, C++, Rust, or assembler provides an opportunity to extend the capabilities of the BEAM. In this chapter, we will use C for most examples, but the methods described can be used to interface almost any other programming language. We will give some examples of Rust and Java in this chapter. In most cases, you can replace C with any other language in the rest of this chapter, but we will just use C for brevity. |
@@ -425,7 +425,7 @@ Imagine implementing a simple BIF to calculate the factorial of a number. The BI |
425 | 425 | 2. Perform the computation efficiently in C. |
426 | 426 | 3. Return the result to the Erlang environment. |
427 | 427 |
|
428 | | -Find the code in erts where bifs are defined: |
| 428 | +Find the code in erts where BIFs are defined: |
429 | 429 | https://github.com/erlang/otp/blob/master/erts/emulator/beam/bif.c |
430 | 430 | or in this case perhaps in https://github.com/erlang/otp/blob/master/erts/emulator/beam/erl_math.c |
431 | 431 |
|
@@ -830,8 +830,8 @@ NIFs are functions implemented in C or C++ (or other languages) that are called |
830 | 830 | They provide a way to dynamically extend Erlang with native code for performance-critical operations or interfacing with external libraries. |
831 | 831 | Improper use can still destabilize the VM, so they should be used cautiously. |
832 | 832 |
|
833 | | -How to use Nifs is nowadays well documented in the link:https://www.erlang.org/doc/tutorial/introduction[Interoperability Tutorial] in the |
834 | | -link:https://www.erlang.org/doc/system/nif.html[Nif section], but we will go through the basics here. |
| 833 | +How to use NIFs is nowadays well documented in the link:https://www.erlang.org/doc/tutorial/introduction[Interoperability Tutorial] in the |
| 834 | +link:https://www.erlang.org/doc/system/nif.html[NIF section], but we will go through the basics here. |
835 | 835 |
|
836 | 836 | ==== Implementing a Simple NIF |
837 | 837 | A simple C-based NIF for fast integer addition: |
@@ -884,4 +884,3 @@ Then in Erlang: |
884 | 884 | Keep NIF execution **short** to avoid blocking the BEAM scheduler. Use NIFs for **performance-critical** operations and **interfacing with external libraries**. |
885 | 885 | **Use dirty schedulers** for long-running operations. |
886 | 886 | Always **validate inputs** to prevent crashes. |
887 | | - |
0 commit comments