Create vs new()

For classes registered with factory we should be using create() and not new(); but I have often seen new() work out in those cases. Could u elaborate as to what difference will using new() introduce in the following case? I mean are there any overheads when we use new() instead of create() in the example below.

Eg::

class_wr_agent extends uvm_component;
bus_wr_driver drvh;

function build_phase(uvm_phase phase);
super.build_phase(uvm_phase);
drvh = bus_wr_driver::type_id::create (“drvh”, this);


endfunction
endclass

In reply to 100rabhh:

You always want to use create() to utilize the UVM Factory.

In reply to 100rabhh:

In order to create a new object the new() will eventually get called. You can either call it directly or use the factory routine create() which in turn will call new();

The advantage of using the factory routine is that, it will be easy to do a factory override. In the above example,if you would like to use a defective driver for the next test, you do not
have to change the test code, instead you do a separate call to set_override_type_by_type(). You will lose this flexibility if you had directly called new() to create the driver.

In reply to 100rabhh:

To add to this discussion, there is overhead in registering with the factory, regardless of using new() or create(). And there is some overhead in using create() versus new(). This has to do with creating the database of factory registrations, overrides, and then searching through that database every time you call create, which could involve lots of string manipulation.

So don’t register classes with the factory if you have no intention of using create(). This is especially important with large amounts of script generated classes like the UVM registers.