[erlang-questions] binary_part/3

Frank Muller frank.muller.erl@REDACTED
Mon Jan 8 20:09:25 CET 2018


OTP team,

Anyone can shed some light on this please?

/Frank

Okay, maybe I'm totally confused here, but is it a pointer to the original
> binary or a new binary?  Looking at the source code it seems to build/make
> a new binary at the end of erts_gc_binary_part().  And from the shell...
>
> 1> A = <<"A cookie is yummy!">>.
> <<"A cookie is yummy!">>
> 2> B = erlang:binary_part(A, 0, 8).
> <<"A cookie">>
> 3> f(A).
> ok
> 4> B.
> <<"A cookie">>
>
> A is gone and we still have B.  Does Erlang actually returns references?
>
> Cheers,
> Alex
>
> On 1/7/2018 at 1:21 PM, "Frank Muller" <frank.muller.erl@REDACTED> wrote:
>
> Thank you Roger!!!
>
> It's a sub-binary:
>>
>>
>> https://github.com/erlang/otp/blob/master/erts/emulator/beam/erl_bif_binary.c#L1915-L1924
>>
>> On 6 January 2018 at 21:38, Frank Muller <frank.muller.erl@REDACTED>
>> wrote:
>> > Hi Everyone
>> >
>> > Is the binary returned when calling binary_part/3:
>> > 1.  a sub-binary pointing to the original one
>> > 2. or a new binary
>> >
>> > Thank you.
>> > Frank
>> >
>> > _______________________________________________
>> > erlang-questions mailing list
>> > erlang-questions@REDACTED
>> > http://erlang.org/mailman/listinfo/erlang-questions
>> >
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180108/637a2070/attachment.htm>


More information about the erlang-questions mailing list