Jump to content

Array of handles


Recommended Posts

What is the difference between storing handle in array like,

ex_obj obj[5];

ex_obj obj1;

for (i=0,i<5;i++) begin

obj1 = new();

obj = obj1;

end

and storing objects in an array?

ex_obj obj[5];

ex_obj obj1;

obj1 = new ();

for (i=0,i<5;i++) begin

obj = new();

obj = obj1;

end

which is an efficient way to do?

Link to comment
Share on other sites

You never store a class object in a class variable. It's always the class handle to the class object that is stored in the class variable.

Both examples store class handles in an array of class variables.

The first example stores a class handle in an intermediate class variable (obj1) before making an second assignment of the intermediate variable to an element of the array (obj). Each time through the loop creates a new object whose handle is stored in each element of the array.

The second example stores a class handle in an intermediate class variable (obj1) only once. Then each time through the loop you assign a new object handle to an element of the array (obj) and then overwrite the handle with the handle stored in obj1. So at the end of the loop, you have 5 elements of the array obj referencing a single object.

I think what you want is this:

ex_obj obj[5];

foreach (obj) begin

obj = new();

end

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...