[erlang-questions] sharing a binary when decoding?

Anthony Shipman als@REDACTED
Fri Feb 3 14:12:01 CET 2012

On Fri, 3 Feb 2012 11:27:32 pm Richard Carlsson wrote:
> 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

What I have in mind will have large binaries that are decoded from socket 
data. I was hoping that this wouldn't duplicate the data.

Anthony Shipman                    Mamas don't let your babies 
als@REDACTED                   grow up to be outsourced.

More information about the erlang-questions mailing list