arcadian

arcadian

Wrote my first NIF and I have some questions

I wrote a simple C++ NIF that gets the unix time. It’s nothing groundbreaking, but it was great to see all of the pieces fit together pretty easily. My questions:

  1. Where is the best place to ask questions about NIFs? (Just making sure I’m not in the wrong place.)

  2. At one point, it looks like there was a package called elixir_make, but I couldn’t get it to work - it kept telling me to install gmake, which was already installed on my system. However looking at elixir_make, it looks like it was created to solve the portability problem of Linux using make and FreeBSD using gmake. Is that a problem that I can solve another way? Since in the end I just hardcoded gmake into the mix.deps file. Some code here:


defmodule Mix.Tasks.Compile.HorizonNifs do
  def run(_) do
      File.mkdir_p("priv")
      {result, _error_code} = System.cmd("gmake", ["priv/horizon.so"], stderr_to_stdout: true)
      IO.binwrite result
    end
    :ok
  end
end
  1. Assuming that I build something worth building, what is the best way to package it so that others can use it? I don’t really understand how normal libraries are packaged (the ones that appear in the deps section of mix.exs), and I read that libraries with nifs have some extra steps due to the makefile and c src. Any tips would be great.

  2. What would you like to see in a NIF-based library? My interest is mostly in data structures, which IMHO seems like an area elixir is lacking in. I also have some ideas related to security and authentication, since those can be computationally expensive.

  3. Not really a question, but I noticed that dirty_nifs have a much higher overhead - in a tight loop I was able to execute far fewer of them. Suggests that the best way to get performance could be by combining normal nif functions with dirty nif functions as needed, so you don’t take the performance hit unnecessarily.

Bonus: Is it okay to enjoy programming both C++ and Elixir? They seem like a great match since they are both good at completely different things. Just gotta make sure my .ex files aren’t full of accidental semicolons LOL …

Appreciate the community and the help!

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New

We're in Beta

About us Mission Statement