Question:
What is difference between deep copy & sallow copy?
Answer:
Deep Copy-In Deep Copy it copies entire page or u can say all objects while in Shallow Copy-It Copies the some of the object Source: CoolInterview.com
Answered by: Oza Pratik N | Date: 10/17/2008
| Contact Oza Pratik N
A "shallow" copy is when the member values are physically copied from one object to another, *including* the values of any pointer or reference members. If there are pointer or reference members, then, those pointers or references refer to the *same* objects as the original object, which is usually a bad thing. That's why you want to define a copy constructor and assignment operator for objects that contain pointers or references.
It's called a "shallow" copy because only the values of the pointers/references are copied, instead of making copies of those referred-to objects and setting pointers to them. *That* is what would be called a "deep" copy, because it's going "deeper" into the structure, copying everything, not just the first "layer". Source: CoolInterview.com
Answered by: 1 | Date: 10/21/2008
| Contact 1
Shallow and deep copy are used for copying data between objects.
Shallow Copy: creating a new object, and then copying the nonstatic fields of the current object to the new object.
If a field is a value type --> a bit-by-bit copy of the field is performed If a field is a reference type --> the reference is copied but the referred object is not; therefore, the original object and its clone refer to the same object.
in C# and VB.NET, shallow copy is done by the object method MemberwiseClone()
Source: CoolInterview.com
Answered by: kokilanaresh | Date: 10/23/2008
| Contact kokilanaresh
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|