Object creation

Is it required to create object inside any task or can we create it even outside ?
and for creating a component is it required to create it inside build phase?

Please answer

Thank you.

In reply to jaswanth_b:

If you are going to use that object in task then yes you need to create a object since declaring a object is not enough. By default the object will be automatic but you can make it static if don’t want to create the object everytime you enter the task.

Its fair uvm practice to build uvm components inside the build phase since the build top down and you can overide the objects by name or instance. Adding them inside the new() is not good idea.

In reply to jaswanth_b:

It would help to explain what you intend to mean by “outside” a task. A simple example of what you were thinking of would work too.

You can construct an object anywhere you can declare a class variable as part of its initial value. And you can construct a object anywhere you can make an assignment to a class variable.

Please see http://go.mentor.com/class-on-classes for more on the terminology I am using.

The UVM recommends creating objects in the build_phase rather than the component’s constructor new() because it makes overriding easier. You cannot override the code in a constructer new().

In reply to dave_59:

My intention is explained in following example:

//if you have an instance of seq_item (for example)
seq_item item; // which is used in task body
item = seq_item :: typeid :: create(item); // created outside task body

//can we "create" it outside task
task body;
 start_item(item);
 finish_item(item);
 // ...
endtask: run

In reply to jaswanth_b:

The problem with your code is you have a procedural assignment statement outside of a procedural block. To fix that, make it a variable declaration initialization.

seq_item item; = seq_item :: typeid :: create(item); // created when sequence gets constructed
task body;
 start_item(item);
 finish_item(item);
 // ...
endtask: run

In reply to dave_59:

Thanks dave,