1. When the owned variables are immutable types, a shallow copy is sufficient. A deep copy is possible, but would only result in additional memory use.
  2. Coming from C++ POV, there would be one scenario that i will use shallow copy : when implementing copy-on-write mechanism.
  3. Flyweight pattern would be an acceptable use of a shallow copy. Lazy copying is also a shallow copy.
  4. Shallow copies are quicker to make, which is often desirable for obvious reasons. The ultimate in shallow copying is obviously just a copy of a reference to the original object. If you're not mutating an object and can guarantee it won't get changed in other ways while you work with it then the more shallow the copy is, the better.
  5. Shallow copies duplicate as little as possible. A shallow copy of a collection is a copy of the collection structure, not the elements. With a shallow copy, two collections now share the individual elements.Deep copies duplicate everything. A deep copy of a collection is two collections with all of the elements in the original collection duplicated.
  6. ShallowCopy points to the same location in memory as 'Source' does. 'DeepCopy' points to a different location in memory, but the contents are the same.
  7. In Simple Terms, a Shallow Copy is similar to Call By Reference and a Deep Copy is similar to Call By Value In Call By Reference, Both formal and actual parameters of a function refers to same memory location and the value.In Call By Value, Both formal and actual parameters of a functions refers to different memory location but having the same value.
  8. Shallow:

    Before Copy Shallow Copying Shallow Done

    Deep:

    Before Copy Deep Copying Deep Done


posted on 2012-09-14 18:27  chuwachen  阅读(157)  评论(0编辑  收藏  举报