Jump to content
hugemx830202

What 's difference between copy and clone?

Recommended Posts

Hi,

From the UVM class reference manual, copy is deep copy, and clone is exact copy, so what does 'exact' copy mean? I guess clone is also deep copy, but the difference with copy(), is that clone() is virtual method, but copy() is not, need your confirm, thanks.

BR

MEIXIAO

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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...