It’s confusing because it “copies” anyway when I update it, but from what I understand it’s just copying pointers most the time, not making some kind of deep copy. Does it make some kind of full copy if I spawn? What if I never modify it?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, when you spawn you need to copy every term that is passed to the spawned function to the heap of the new process.
When you are updating a list or dict, any unchanged elements are not copied because the pointers to these are in the same heap and can be used for the new term. Consider the following example:
In this case for the
Bterm you just need to assign memory in the heap for one cons cell whose first element is the term0and the second element is a pointer to the first cons cell of theAlist. TheAlist is in the same heap.When you spawn, the new process has its own heap, so all the data it uses must be copied there.
If the spawned process is not going to access all the elements in the large data structure, it makes sense to either extract the relevant data before spawning, or using ETS tables (when you pass an ETS table only the table reference is passed but you need to copy in or out any element that you change or access).