+ 1
Difference between deep copy and shallow copy
2 Respuestas
+ 2
deep copy ->
All values are being copied over.
I'm copying to a different object.
Hence the object itself is copied.
Shallow copy ->
The reference of the object is being copied to a different variable.
Since you never specified the language, this example will be with Java.
Example/
int[] array = {5,3,1};
// An array is an object
int[] temp = array;
// SHALLOW copy
temp[0] = 10;
// This changed the array 'array'.
// temp is pointing to the same array, so both are modified.
//DEEP COPY
int[] deep = new int[array.length];
for(int i = 0; i < deep.length; ++i)
deep[i] = array[i];
// All values were copied over, however this is a brand new array.
This means changing a value of the array 'deep' will not also change the value of the array 'array'.
0
Here is a good explanation on something other than a primitive type.
http://javaconceptoftheday.com/difference-between-shallow-copy-vs-deep-copy-in-java/