[erlang-questions] sharing a binary when decoding?

Richard Carlsson <>
Fri Feb 3 13:27:32 CET 2012


On 02/03/2012 01:11 PM, Anthony Shipman wrote:
> If I decode a binary B using binary_to_term() and get a result like
> {1, 2,<<"abc">>} is it guaranteed that a binary in the result is a sub-binary
> of B?

I can't see why the language would want to give such a guarantee, since 
that would prevent making more efficient implementation choices in 
certain cases. For example, if the resulting binary is quite short, as 
in your example, it's probably better to just copy the data to a new 
binary. On a 64-bit machine, one could even use an immediate 
representation of a single word for very short binaries, if there is 
room in the tagging scheme. (I don't know if Erts does this already.)

    /Richard



More information about the erlang-questions mailing list