Home Ask Login Register

Developers Planet

Your answer is one click away!

zero_coding February 2016

What does binaries mean?

When I import an exs file that contains a function as follow:

iex(6)> import_file("mymath.exs")
{:module, MyMath,
 <<70, 79, 82, 49, 0, 0, 4, 212, 66, 69, 65, 77, 69, 120, 68, 99, 0, 0, 0, 147, 131, 104, 2, 100, 0, 14, 101, 108, 105, 120, 105, 114, 95, 100, 111, 99, 115, 95, 118, 49, 108, 0, 0, 0, 4, 104, 2, ...>>,
 {:square, 1}}

What does binaries exactly represent?

Answers


Onorio Catenacci February 2016

The numbers are the binary representation of the imported module.


Mauricio Carvalho February 2016

Once Elixir builds on top of Erlang to provide distributed and fault-tolerant, this sequence of number <<70, 79, 82, 49, 0, 0, 4, .... ...>> represents your binary code who is running inside your Erlang VM (BEAM).

As a real-life example you can use it to make hot code deployments. How? Using a rpc call with load binary, passing your binary code as arguments.

I.e

{_Module, Binary, Filename} = code:get_object_code(Module).
 rpc:call(Node, code, load_binary, [Module, Filename, Binary]).

Follow a really good article about how it works and how you can manipulate your bytecode between erlang nodes. http://seanstavro.com/blog/elixir-slave-nodes/

Cheers, @MC

Post Status

Asked in February 2016
Viewed 2,197 times
Voted 10
Answered 2 times

Search




Leave an answer


Quote of the day: live life