Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Framework  »  Copying vs. Cloning  »  Results and Conclusion
Copying vs. Cloning
by Phil Eakins | Published  02/09/2006 | .NET Framework | Rating:
Results and Conclusion

The results of the test are tabulated below:

Testing for Existance of Second Array

There is a facility to compare pointers to see whether they point to the same Object on the Managed Heap,  Array1() is Array2().  

I have used this comparison to provide the text for the ‘Independence’ Label on the lower right corner of the Form in the accompanying program. The test takes place after the data is written for the second time.

Whilst it provides accurate results for the System Types it cannot serve for the User Designed Types as (although the Pointers might not be to the same Object) the content of those Arrays is, in some cases, not the required independent copy (see Table 4 with Table 5).


This has been a most interesting exercise and in doing the research I have learned some valuable lessons about how .NET 1.1 organises variables in memory. In particular, I now know what to avoid!

As can be easily seen, the copying of an array of System Types if straightforward, but making a straight copy of the Array pointer to another variable should be avoided, unless a ‘second’ copy is required of course.

User Designed Types are also straightforward so long as there is no type referred to within the Object, a little more complicated if there is, and impossible to do by a Native Framework Method if the Object referred to does not, itself, support cloning.

However, one thing that stands out very clearly indeed is that any copy involving the CloneObject Method/Function will succeed no matter what, provided that all of the objects involved are serialisable.

All of the tests were carried out using the associated program (developed using VS2003) which can be downloaded, with the source code, from the link.  Please feel free to explore different options and to change the code as you see fit.  I should, however, like to hear of your experiences so that I can keep this paper up-to-date.

No doubt there will be questions and comments, which I will be happy to deal with on-line.


Sponsored Links