Erlang / Erlang Advanced Interview questions
Why is copying a large list between processes more expensive than copying a large binary?
A large binary (over 64 bytes) is stored off the process heap and reference-counted, so sending it in a message copies only a small pointer-sized reference — the actual byte data never moves. A list, by contrast, is a chain of individually heap-allocated cons cells with no such off-heap, reference-counted representation.
flowchart LR
subgraph Binary send
A1[Large binary off-heap] --> A2[Message copies a small reference]
end
subgraph List send
B1[List of cons cells on sender heap] --> B2[Every cell deep-copied into receiver heap]
end
When a list is sent in a message, the entire structure — every cons cell and every element — is deep-copied into the receiving process's heap, since processes share no memory and lists have no built-in sharing mechanism the way large binaries do. For data that's genuinely large and needs to move between many processes repeatedly, converting it to a binary (or storing it in ETS and passing a key/reference instead) is the standard way to sidestep this cost.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
