[erlang-questions] Binaries

Mihai Balea mihai@REDACTED
Thu Mar 3 22:21:38 CET 2011


On Mar 3, 2011, at 2:56 PM, Bob Cowdery wrote:

> One of the things I need to do is move large binaries of up to 4096
> floats around between processes. As there are real-time constraints on
> processing this data I just wanted to check a few things.
> 
> The docs say that large binaries are zero copy (presumable only in the
> same node). How exactly does this work in a lock free environment?

Large binaries are stored in a separate heap and are garbage collected separately.
A reference is passed around between processes (on the same node)

> 
> 1> T=[1.0].
> [1.0]
> 2> B=term_to_binary(T).
> <<131,108,0,0,0,1,99,49,46,48,48,48,48,48,48,48,48,48,48,
>  48,48,48,48,48,48,48,48,48,48,...>>
> 3> size(B).
> 39
> 
> The docs also say that binary data is efficient. Why does 1 float
> convert to 39 bytes? This ratio only reduces slightly with larger lists
> . If erlang holds floats internally in 64 bit format I don't understand
> why it needs 39 bytes.

First of all, in your example, T is a list containing one float element.
Secondly, if you want to store a float in a binary, a better way would be

1> F = 1.0.
1.0
2> B = <<F/float>>.
<<63,240,0,0,0,0,0,0>>
3> size(B).
8

Mihai


More information about the erlang-questions mailing list