The best way of using struct, class, and array

Hello, all.

I implement functions for verifying DUT, but its performance is not good.
I use struct type variable and queue, and associative array for comparing.
I want to enhance its performance. So, I wonder about the best way to use struct, class, and array.

My questions are below.

  1. If I push_back a struct variable into a queue, will all member variables in the struct variable are copied into a queue?
    If it is true, I think often pushing a struct variable into a queue affects performance.

  2. If I push_back a class object into a queue, will the only handle be copied into a queue, not all member variables?
    If it is true, I think using a class object instead of struct is better from a performance point of view.

  3. If I delete an element of the middle in the queue, will all elements after the deleted index are moved(copied) to one left for adjusting an index?
    If a queue in the systemVerilog is implemented as a linked list, I think it does not matter. But, If the queue is implemented as a vector or array, I think deleting an element in the middle of the queue can matter for performance.

  4. We can use find_xxx methods of array. I think for performance reasons you shouldn’t search in the array. Is the find_xxx methods of an array slow?

Are all my questions affected by the simulation tools…?

And I don’t want to copy struct variables through arguments of a function. So, I use ref or const ref keyword on the arguments.
Anyway, please let me know if you know the best way to use struct, class, array in terms of performance.

Thank you for your comment.

In reply to jh_veryveri:

First, I suggest using your tool’s profiling capabilities to make sure you are spending effort in the right places in getting the best performance.

Push/pop of a queue involves allocation/deallocation of an array element to hold a value. Other than that, there is no difference between push/pop versus making an assignment to another variable, you are always coping a value. That includes an input/output arguments of function that copies its value upon entering/exiting the the call.

Then you need to understand that making assignments to class variables is copying the handle referring to a class object, not the object itself. That means a function argument that is a class variable should be an input or output, not a ref. A ref argument makes it a double reference.

Finally, using the builtin find() methods will certainly be more efficient than code you could write yourself to do the exact same thing in most cases. Sometimes using an associated array might be more efficient in looking up key values.

In reply to dave_59:

I always thank you, Dave.

I understand your reply for Q2 and Q4. The assignment of a class object is a reference. The built-in find() method is good but using an associated array is recommended if I can use associated array.

I still wonder Q1 and Q3. By inferring Q2, I may be able to know the answer for Q1.
By inferring to Q2, I think an assignment of a struct variable is a copy. If so, I think inserting a struct variable in the queue can cause a performance hit. What do you think?

And Q3… I can’t find the answer in the IEEE 1800-2017 Standard for SystemVerilog.

In reply to jh_veryveri:

Q1: yes, pushing a struct onto a queue means copying the struct. For a large struct, wrapping that data in a class and copying its handle might be more efficient

Q3: the IEEE standard for SystemVerilog does not say anything about how to implement any construct. There are other ways of implementing a queue besides a linked list or array; sometimes a combination of ways. I would assume pushing/popping one element of a queue from the front or back of the queue will be most efficient.

In reply to dave_59:

Thank you so much, Dave.

Your comment will be of great help to improve the performance of my implementation.

Thank you so much again. :)