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

Tee
can someone please explain to me how Enum.reduce works with maps
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement