Jump to content

What 's difference between copy and clone?


Recommended Posts

Hi MEIXIAO,

The UVM clone method is used to provide a deep copy of an object. We can call clone() on any object, and it will use the clone() method of its actual class, without the calling code needing to know what that class is.

Clone first allocates new memory for the object, then copies over each field to the new object. If a field is an object handle, then instead of copying the handle (which would do a "Shallow" copy) you would call fieldname.clone() to recursively allocate memory for that field (a "Deep" copy).

Link to comment
Share on other sites

clone() means construct followed by a call to copy(). clone() is virtual so that you can construct the same object type as the one you started with. clone() calls copy() to perform a deep copy of the object type you just created. The copy() method by itself just copies class member values from one object to another. Normally, the copy() method only copies the class members for the current class type, then it calls super.copy() to copy the class members of the base class.
Link to comment
Share on other sites

  • 4 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...