Need clear understand of handle

We create handle and objects for a class.What are the major differences between handle and object.When we need to create handle.

Hi,
See a screenshot from our regular VSV training (http://www.cvcblr.com/trng_profiles/CVC_LG_VSV_profile.pdf) that covers this topic.

HTH
Ajeetha, CVC

In reply to Ajeetha Kumari CVC:

I like to think of three distinct concepts: class variables, handles and objects.

A class object is an instance of a class definition that you create when you call its constructor function - new(). In SystemVerilog, all class objects are created dynamically; on or after time 0. The LRM does not specify how or when an object can be destroyed - only when it cannot be destroyed.

A class variable is variable whose value represents a reference to a class object. Like any other variable, the lifetime of a class variable depends on how and where it is defined (static, automatic, or dynamic).

The value that represents a reference to class object is called a handle. You can never see or represent the literal value of a handle (except for the special handle: null). You must use the class variable in an expression to reference members or methods in the class object using the class handle stored in the variable.

In reply to dave_59:

Hi Dave,

Iam pretty confused with your explaination.Actually class variables means either Objects/handles which will be created in below fashion.

Class_name clss_variable;//class variable nothing but object/handle.

I just need when we use handle and when we use object,What is the difference between both of them.

Regards
Bharath

In reply to Lucky:

Bharath

If you run this complete example

module top;
class class_name
  int i;
endclass
class_name class_variable;;
initial $display("Hello World");
endmodule

you will have created a static variable class_name but no class object. So no handle exists to class_name. Now a call to the constructor.

initial begin
        class_variable = new();
        class_variable.i = 1;
        $display(class_variable.i);
       end

new() is a function that returns a handle to an object of class_name.class_variable.i means use the handle stored in class_variable to reference an object, and select variable i of that object. In C/C++, this would look like the pointer reference class_name->i; In SystemVerilog, you never use the object directly, you always reference is using a handle stored in a class variable.

1 Like

In reply to dave_59:

Hi Dave,

Thanks,Your explanation is pretty clear.

Regards
Bharath

In reply to dave_59:

Hi Dave,
What happens when I pass the object handle as an input argument to a function ?
Is it a pass-by-value or pass-by-reference ?

If the function changes the value of a variable inside the object, will it affect the original object’s handle ?

In reply to Mustafa Kamal:

https://verificationacademy.com/forums/systemverilog/can-task-arguments-which-are-class-variables-object-handle-be-always-treated-pass-ref-type-argument#reply-75354