Handle
A handle is a pointer to an object created from a Class. Handles are crucial in dynamically creating and managing Objects during simulation.
Syntax: Handle
Ex_class cl_obj; // declare a handle
cl_obj = new(); // allocate a Ex_class object
When the handle ‘cl_obj’ is declared, it is initialized to a null value. Call the new() function to construct the Ex_class object. The new function allocates space for Ex_class, initializes the variables to their default values (0 for 2-state and x for 4-state variable), and returns the address where the object is stored. This is similar to calling a malloc function in C language. The new function is called the constructor, as it builds the object.
Note: You DECLARE a handle and CONSTRUCT an object.
Difference Between new( ) and new[ ]
- new( ): is function called to construct an object.
- new[ ]: is an operator used for arrays.
Allocating Multiple Objects
Ex_class cl_obj1, cl_obj2; // declare two handles
cl_obj1 = new(); // allocate the first object
cl_obj2 = new(); // allocate the second object