I've found that Elixir programs can run C code either via NIFs (native implemented functions) or via OS-level ports. Having read those and similar links, I'm not a hundred percent clear on when to use one or the other method (or something else entirely?), and feel it would be good to have a direct comparison available, for myself and other novices. Can anyone provide?
Running C code in Elixir/Erlang: Ports or NIFs?
4.3k Views Asked by Vivian At
1
There are 1 best solutions below
Related Questions in C
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in COMPARE
- requesting excel formula to compare columns but going in order and skipping blanks
- How to check for matches where fields are different?
- Case-insensitive map key where key is Pair<String, String>
- Dropping rows that do not match values from another column
- How to compare two integer fields in a model method in django?
- php: comparing string with boolean value
- Compare row values in excel and store time value in a variable
- Smart Compare json files
- Comparing two dataframes and highlighting the differences
- Python Pandas: Find the difference of two dataframe
- Comparing two data frames with condition and removing all that not qualified
- Query to compare two comma separated number string
- I wonder what is impact of xml and csv on google bot?
- Compare Nmea line in a single file
- check status connected nordvpn bash script
Related Questions in ELIXIR
- Phoenix in a docker dev environment - generated code can't be saved from VSCode
- Microsoft Teams, Graph API, send message to channel InsufficientPrivileges MessageWritesBlocked-Thread is not marked for import
- Can someone tell me what's wrong with mi Task.await?
- Is there a Sonar-Elixir plugin compatible with SonarQube 10.4.1?
- How to use Elixir pattern matching to check if a list's item startswith a given string(in a variable)?
- Error `unknown application: :nif_bartender` when compiling Elixir NIF
- How to use compiled erlang modules in an elixir project?
- OnVif authentication failed for Milesight camera
- Debugging Boggle Solver Implemented in Elixir with Trie Structure
- Elixir Enum.group_by converts integers to ASCII Chars
- Disambiguate "arity denotation" and "arithmetic division" in Elixir
- LiveView [LiveMotion] Motion element not found, make your target a LiveMotion.motion component
- What exactly is flushed by flush/0 in Elixir?
- Attempting to understand the difference in computed result for a Math.imul (javascript) recreation in Elixir
- Cronjob does not work for the local asdf elixir path
Related Questions in BEAM
- PulsarIO.read() failing with AutoValue_PulsarSourceDescriptor not found
- How to use compiled erlang modules in an elixir project?
- Event sourcing with CDC and stream processing
- ModuleNotFoundError message when run gcp dataflow pipeline with python
- Who is the sender of Erlang's trace messages and what can I assume based on it?
- When using Apache Beam locally, how to utilize persistant caching for queries in BigQuery?
- State in Singleton object changes between workers in Scala
- How does elixir performs slicing
- Can I load compressed jsonl data from GCS to BigQuery and add an additional date column using DataFlow
- Apache beam data trigger when using event time trigger
- Apache Beam Publish Kafka Message with KafkaIO and KafkaAvroSerialization for GenericRecord
- Apache Beam Streaming Write/Read BigQuery
- Programmatic Retrieval of Job Information with 'workerDiskType' from Google Cloud Console
- Configuring pipeline options in Apache Beam - Touring example fails
- Spark Task Data loss after worker dies in Java
Related Questions in LANGUAGE-BINDING
- Is there a way to generate a vega(-lite) graph from java (other than programming one, from scratch)?
- Use Python to call a JavaScript function that is on a webpage
- Writting a wrapper for a customized lua-based scripting language
- language binding error with Fortran: why won't it link to MPI library?
- Catching fortran runtime errors and signals in C++ binding
- Terminology for function interface/DLL used only to fix parameter types between different languages?
- How a bridging header works in Xcode?
- pybind11 cmake example cannot find the main function
- How can I write a library usable from multiple languages?
- Running C code in Elixir/Erlang: Ports or NIFs?
- calling c code from lua
- What kinds of C++ functions can be placed in a C function pointer?
- Does Qt/Gtk+ allow programming in two languages at once?
- How does calling C or C++ from python work?
- Objective-C binding pointer array to C#
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
What are ports?
Ports are basically separate programs which are run separately from the Erlang VM. The Erlang VM communicates with the running port over standard input/output, and the resulting port lives behind an Erlang process that owns it and can facilitate communication between the port and the rest of your Erlang or Elixir application. Ports are "safe" in the sense that if the port crashes, it doesn't bring down the whole Erlang VM.
Porcelain might be of interest as a possible improvement and expansion over what's already provided in the
Portmodule.System.cmd/3also uses ports in its underlying implementation.What are NIFs?
Native inline functions or "NIFs" are functions defined in what are essentially shared libraries / DLLs loaded by the Erlang VM and written using some language which exposes a C-compatible ABI. NIFs are more efficient than ports (since they don't have to communicate over
STDIN/STDOUT) and are simpler in many respects (since you don't have to deal with encoding and decoding data between your Elixir and non-Elixir codebases), but they're also much less safe; a NIF can crash the Erlang VM, and a long-running NIF can potentially lock up the Erlang VM (since the scheduler can't reason about native code).What are port drivers?
Port drivers are kind of an in-between approach to integrating external code with an Erlang or Elixir codebase. Like NIFs, they're loaded into the Erlang VM, and a port driver can therefore crash or hang the whole VM. Like ports, they behave similarly to Erlang processes.
When should I use a port?
When should I use a NIF?
When should I use port drivers?
What do you recommend?
There are two aspects to weigh here:
If you want maximum safety behind a process-like interface, go with a port.
If you want maximum safety behind a module-like interface, go with a module with functions that either wrap
System.cmd/3or directly use a port to communicate with your external codeIf you want better efficiency behind a process-like interface, go with a port driver.
If you want better efficiency behind a module-like interface, go with NIFs.