[erlang-questions] when is data copied?

Dmytro Lytovchenko dmytro.lytovchenko@REDACTED
Fri Mar 17 11:31:56 CET 2017


Data is stored in process heap most of the time.
As long as data is moved INSIDE the process, it is NOT COPIED, only a
pointer is passed.
If the data ever leaves the process, a message for example, it will be
COPIED to its new owner.
If the data is moved to or from ETS, it behaves similarly, it is COPIED
(ETS has own heap separate from any process).
If the data is moved between a process and a port, it is COPIED (ports
behave similar to processes, and own resources in a similar way)
Large binaries >64 bytes are NEVER copied, instead they are reference
counted and reference is shared between processes. This is why you want to
GC all processes which touched a large binary periodically, otherwise it
may take a long time before the binary is freed.

2017-03-17 11:24 GMT+01:00 Xavier Noria <fxn@REDACTED>:

> I would like to have a mental model for data copying in Erlang.
>
> By that I mean immutability is in my view a property of an API, but I
> suppose the implementation, compiler optimizations, etc., can precisely
> leverage that property to reuse stuff behind the scenes for performance.
>
> Would you recommend any particular article, talk, book, ..., that would
> help me get an idea of how that works in Erlang?
>
>
> _______________________________________________
> 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/20170317/bb7f2ebb/attachment.htm>


More information about the erlang-questions mailing list