Shallow Copy , Deep Copy , Memberwise Copy ,Bitwise copy

hello ppl,

i searched thru google but i didnt find the exact explanation for

constructors.

Shallow Copy , Deep Copy , Memberwise Copy ,Bitwise copy

i got some conflicting answers..

and what is the difference between them..

.pls help me..

manish



Answer this question

Shallow Copy , Deep Copy , Memberwise Copy ,Bitwise copy

  • Ty Y

    Shallow copy = Bitwise copy.

    Deep copy = Memberwise copy.

    Long story short, a shallow copy only copies the binary, in memory, print of a class. A deep copy "dives into" the members, and copy their logical data.

    Example: If you've got a class with one member, which is a pointer of irrelevant type, a shallow copy would duplicate the address, leaving you with two classes with pointers to the same value. A deep copy would copy what the pointer addresses, again giving you two classes, but each with a pointer to its own value. Not only will the class be copied, but also whatever types it contains.



  • Bobby110uk

    Just to be pedantic the compiler actually doesn't generate code that copies the object one bit at a time - it is at least one byte at a time. But the underlying meaning is the same: the way I think of it is a shallow/bitwise copy can be done using memcpy while a deep/member wise copy requires calling copy constructor/assignment operators for user-defined types. Note: for built in types, like int, char, etc., there is only one way to copy the object and that is a bitwise copy.

  • Sascha Zeidler

    Hi,

    I was confused about these expressions too and looked at your explanations and they were very sensible. But while I was looking at the object browser in visual studio 2005 I saw the following:

    protected object MemberwiseClone()

    Member of System.Object

    Summary:

    Creates a shallow copy of the current System.Object.

    Return Values:

    A shallow copy of the current System.Object.

    This indicates to me that a memberwiseclone is a shallow copy not a deep copy as you have stated above. So I am still confused as to the correct definitions of a memberwise, bitwise, shallow and deep copy. Perhaps the object browser is wrong or perhaps there is some question over these definitions.

    Kind Regards

    Andy


  • zapacila89

    thanks friends for helping me.

    finally i got rid of all confusion

    thanks a lot

    manish


  • Rusty Trawler

    Yes, "byte by byte" is more appropriate. That "bit by bit" thing was just a form of speech like "bitwise copy".

    Regards

    Sahir


  • mark aoki

     

       When you pass an object by value if you haven't made provision for a copy constructor the compiler assumes a bit copy. That means the object is copied bit by bit without considering the (for lack of a better word) "semantics" of the object. Shallow copy and bitwise copy are the same thing.  

    Regards

     Sahir


  • Shallow Copy , Deep Copy , Memberwise Copy ,Bitwise copy