I intend to manipulate binaries using NIFs for an app which I'm planning to code in Erlang. The gist links to the cpp file and erl file for the NIF are given below.
[Erl Gist Link] https://gist.github.com/abhijitiitr/3a5bc97184d6dd32f97b
[C++ Gist Link] https://gist.github.com/abhijitiitr/24d2b780f2cdacebfb07
Basically I'm trying to do a simple test. Share binaries across NIF calls and successfully manipulate them with successive NIF calls.
If you test the code in erlang REPL by
c(binary_test).
Ref=binary_test:open(<<1>>).
binary_test:increment(Ref,<<3>>).
The binaries stored changes in between the NIF calls. The REPL output for the third command is
1
3
60
60
<<"?">>
I passed <<1>>
during the initialize phase. Why did it change to <<60>>
? I'm unable to figure out whats happening here. Can somebody point out the error?
C++ compile instructions
clang++ -std=c++11 -stdlib=libc++ -undefined dynamic_lookup -O3 -dynamiclib binary_test.cpp -o binary_test.so -I /usr/local/Cellar/erlang/17.0/lib/erlang/erts-6.0/include/
on my Mac.
Also I wanted to ask about concurrent processes manipulating a shared resource in NIF. Is that possible or there is a rule that NIFs have to be accessed in a single Erlang process.