[erlang-questions] Adding binary data to a list

Theepan vasdeveloper@REDACTED
Mon Jan 25 17:33:27 CET 2016


Thanks Richard, for the clarification. Yes - I was referring to
interprocess communication..

Regards,
Theepan

On Mon, Jan 25, 2016 at 5:08 AM, Richard A. O'Keefe <ok@REDACTED>
wrote:

>
> On 24/01/2016, at 9:23 am, Theepan <vasdeveloper@REDACTED> wrote:
> > If I add the same binary data to different lists, will it be copied? I
> know for a fact that binary data are referenced, but not sure in list
> making case.
>
> Suppose you have this code:
>
>    X = ...any arbitrary Erlang term...
>    P = ...any list you like...
>    Q = ...any other list you like...
>    P1 = [X|P],
>    Q1 = Q ++ [X]
>
> X is not copied, no matter what it is, no matter how small,
> no matter how big.  Making P1 copies nothing, just creates
> one new pair.  Making Q1 copies the spine of Q, but not the
> elements of Q, and not X.
>
> You are probably thinking about the fact that
> large binaries are *not* copied when they are
> sent to another process, and that they are
> reference counted for that purpose.
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160125/6d737854/attachment.htm>


More information about the erlang-questions mailing list