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

Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
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
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
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

Other popular topics Top

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
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
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

We're in Beta

About us Mission Statement