[erlang-questions] map over bitstring

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Fri Oct 22 12:11:51 CEST 2010


On Fri, Oct 22, 2010 at 11:25 AM, Morten Krogh <mk@REDACTED> wrote:
> Hi,
>
> I would like to understand what happens under the hood with this zip
> function, especially
>
> <<R/binary,X,Y>>
>
> Does this function work by copying R all the time, and then having the
> garbage collector
> collect the old R immediately, or can BEAM share R in some way.

Binaries are put into their own Arena on the heap where they are
ref-counted for their use. Since a binary can never hold a pointer to
a binary, this idea is safe w.r.t cycles. Destructuring a binary can
then be done with a triple, (P, O, L) where P is a pointer to the
binary, O is the offset integer and L is the length integer. In
effect, deconstructing the binary is fast. Constructing the binary is
done in a way which gradually allocates more and more data for the
binary (somewhat like a growing array) so that is also reasonably
fast.

This is the quick overview. The details, which you should peruse is at,

http://www.erlang.org/doc/efficiency_guide/binaryhandling.html



-- 
J.


More information about the erlang-questions mailing list