[erlang-questions] [Q] Copying memory between processes
David Hopwood
david.hopwood@REDACTED
Thu May 24 17:37:37 CEST 2007
Bjorn Gustavsson wrote:
> Ladislav Lenart <lenartlad@REDACTED> writes:
>
>>But as soon as this structure is sent to one other process
>>the system is suddenly out of resources. The only reason
>>this could happen (that I could think of) is: When the
>>structure is copied to the heap of the other process, the
>>identity is not preserved, that is each item references its
>>own list of previous items (though equal). This would explain
>>expontential growth of the memory.
Quadratic in the number of items, actually. But that's bad enough.
> Yes.
I'd say this was a bug. Even if this degree of sharing in a data structure
is unusual, it is not pathological enough that this increase in memory
usage should be considered acceptable.
>>Am I right? And if it so, what is the reason (performance)?
>
> Yes. In typical applications, shared data structures are uncommon.
A deep copy that preserves sharing can be implemented efficiently.
The easiest approach is to use forwarding pointers: as you copy an
object, set a pointer in its header to point to the copy.
--
David Hopwood <david.hopwood@REDACTED>
More information about the erlang-questions
mailing list