c# Thread Safe Deep Copy

后端 未结 1 638
滥情空心
滥情空心 2021-02-20 17:04

I have been reading alot of the other questions as well as alot of google searches and I\'ve been unable to find a clear solution.

Based on some best practices I\'ve rea

相关标签:
1条回答
  • 2021-02-20 17:52

    As to the cloning, stack overflow already has a good answer.

    Deep cloning objects

    as for thread safety, I would imagine the only guarantee is if you put locks around your member variables during your copy.

    Update:

    Ok, I've done some research. I think the most elegant way to ensure the thread safety of your members is for the calling threads to hold locks on the object instead of trying to implement it inside your class. Also, implement the ICloneable interface and then you can just do a binary copy of the entire object easily. See the answer in the link I posted above. Of course, you could still implement locks for your static members inside your class easily.

    0 讨论(0)
提交回复
热议问题