WebForm-- shallow copy and deep copy

Note: This article from the finishing connection  https://www.cnblogs.com/echolun/p/7889848.html  , thanks for sharing bloggers

to sum up:

1, a shallow copy: just copy the name of the variable, not the value of the variable copy - usually a reference type, the value of a variable path, the same path, point is always the same value, regardless of whether the change in value

Deep Copy: Copy both variable name, while the value of the variable copy - usually a reference type

2, a simple and effective method for deep copy (via conversion type):

var B = A;
B = JSON.stringify(B);
B = JSON.parse(B);

 

. a basic types - the name of the value stored in the stack memory , for example, let a = 1;

When you b = a copy, stack memory will open up a new memory, such as this:

 

. b reference data types - the name of the presence of the stack memory value is present in the heap memory, but the address stack memory will provide a reference point values in the heap memory :

When b = a copy, the copy is actually a reference to the address, rather than the value of the stack inside.

When we a [0] = 1 when array to be modified, since the points a and b are the same address, so naturally also influenced by b, which is called a shallow copy.

 

That, if the heap memory has opened a new memory dedicated to storing b value, just as the basic type, would not you achieve a deep copy of the results

Guess you like

Origin www.cnblogs.com/qq450867541/p/11130152.html