Re: Deep Copying Techniques?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Bob Powell [MVP] (bob_at__spamkiller_bobpowell.net)
Date: 12/18/04


Date: Sat, 18 Dec 2004 18:42:24 +0100

I think the short answer is no.

Any arbitrary object may itself have references to objects that don't
provide deep copies of themselves. A deep copy is really only good for a
specific object that provides such a copy from it's own implementation.

To attempt to deep copy using reflection to discover the object requirements
and then Activator to create instances of objects would potentially be
disastrous. What would happen for example if an object declared a
constructor with an Object parameter which internally it cast to some class
or another. You'd never be able to divine from the constructor signature how
to instantiate the object.

I think you're flogging a dead horse on this one.

-- 
Bob Powell [MVP]
Visual C#, System.Drawing
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Steve - DND" <steve!@!digitalnothing.com> wrote in message
news:%23wHQrWS5EHA.2600@TK2MSFTNGP09.phx.gbl...
> Is there any way to easily deep copy an entire object? Maybe something
with
> unsafe code to make a full and completely duplicated copy of an object
with
> no reference ties to the original? I want everything copied, public,
> private, internal, events, etc...
>
> Thanks,
> Steve
>
>


Relevant Pages

  • Re: Custom Surrogate
    ... I need to do a deep copy of my object but I do NOT want to copy the objects ... The MemberwiseClone method creates a shallow copy by creating a new ... consider an object called X that references objects A and B. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "deep copy" with VisualWorks?
    ... references or pointers to objects in the copied array. ... then I tried "dcopy," which seemed to do the trick, although it has ... some strange reference in the comment to creating a "smart deep copy," ...
    (comp.lang.smalltalk)
  • Re: sizeof in java! need help
    ... It's trivial to write a reflection-based method that gets the deep size, but normally, you do not really want the deep size, but something between the flat size and the deep size. ... you want to know the size of the object itself plus the size of the referenced objects that are not referenced by other references. ...
    (comp.lang.java.help)
  • Re: Returning array: reference or deep copy?
    ... > Ryan Stewart wrote: ... >> Always references. ... If you want a copy (deep or shallow), ...
    (comp.lang.java.programmer)
  • Re: Our future generation....sadly
    ... For example "how do we ensure that solar collectors work with the ... supplementary "why is it so deep" is better than your Ancient ... Nice one, Steve. ... What a saddo "Bod" must be! ...
    (uk.legal)