Copy and Clone in UVM and OVM Correct difference?

Hi,

Lets say I have 2 class handles “b” → base class handle. d → derived class handle.
Assume at this point only “b” object is created with new() and probably some more updates to members of “b”, not yet for “d” though.

To put a statement equating copy & clone.
“d=new(); + b.copy(d); <=> $cast(b,d.clone);”

Is this statement correct or is only difference b/w them? are there any other differences with Clone and Copy?

Thanks
Parveez

First, remember that copy() calls do_copy(), which you must define to map the fields from the argument to the object whose copy() method you called. Presuming that you defined do_copy() to map all members of a ‘b’ object to another ‘b’ object:


class b extends uvm_object;
  `uvm_object_utils(b)
  bit f1, f2;
  ...
  function void do_copy(b rhs);
    f1 = rhs.f1;
    f2 = rhs.f2;
    ...
  endfunction
endclass

then ‘d’ does


class d extends b;
  `uvm_object_utils(d)
  bit f3;
  ...
  function void do_copy(d rhs);
    super.do_copy(rhs); // copy 'b' elements
    f3 = rhs.f3;
    ...
  endfunction
endclass

So, if b already exists, and you’ve just created a new d, then b.copy(d) will take the default values of all ‘b’ fields in ‘d’ and overwrite whatever you put in ‘b’. Any of the d-specific fields (f3, for example) would be lost.
The clone() method does a create, followed by a copy, so ‘d.clone’ gives you a new d object with the same values as the existing d. When you $cast that to the b, then only the b-specific fields are copied (f1 and f2 above).
The only difference between ‘new(d);b.copy(d)’ and '$cast(b,d.close);" is that the clone() call creates a new object that will later be garbage-collected, so it’s a bit less efficient.
In any case, I think you have your arguments backwards since the new d will overwrite whatever fields you previously updated in ‘b’.

In reply to tfitz:

Thank You.