[erlang-questions] Binaries

Adam Kocoloski adam.kocoloski@REDACTED
Thu Mar 3 22:18:28 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?
> 
> 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.
> 
> Bob

Hi Bob, I think you're looking for the {minor_version, 1} option:

http://erldocs.com/R14B01/erts/erlang.html?i=1&search=term_to#term_to_binary/2

1> byte_size(term_to_binary(1.0, [{minor_version, 1}])).  
10

Regards, Adam


More information about the erlang-questions mailing list