Assign queue values to dynamic array

suppose i have a queue in my monitor , so i will push_back values in it , but now i want to assign the values to an dynamic array in my transaction {without changing its size } one way to do is
mon_tran.data=newdata_que.size();
where data_que is the queue declared in monitor , data is the dynamic array in transaction , and mon_trans is the object created for transaction
problem in it is it will assign it the size of data_que , but i am randomizing the data in transaction , but i want to only change the values inside the data , by data_que , instead of size so how to do it ??

In reply to mittal:

Can you try mentioned solution to copy queue element to dynamic array?

In reply to mittal:
You can just make an assignment from queue to dynamic array, and the dynamic array takes on the size of the queue

mon_tran.data=data_que;

If you mean to say that your are randomizing the dynamic array with a size larger than the queue, and want to insert the queue into the dynamic array leaving the additional elements with their values, you can use a for loop

for(int index=0;index<data_que.size && index < mon_tran.data.size; index+)
    mon_tran.data[index]=data_que[index];

If that is not what you meant, please show a complete example.

In reply to kerulmodi:

yes , but i want to keep the size same as that of dynamic array , in copying the elements it will have the same size as that of queue , for eg
data ={ 1,2,3,4 } // data is a dynamic array in transaction
data_que = { a , b } // it is declared in monitor

now i am want to assign values to data from data_que in such a way that
data = { a,b, 0,0,}

In reply to mittal:

So you want the extra data elements to be zero-ed out, instead of keeping the random data (a new requirement not originally mentioned).

You you zero out mon_tran.data a number of ways before executing the for loop shown above. For example

mon_tran.data = new[mon_tran.data.size()];

or you can modify the loop

for(int index=0;index < mon_tran.data.size; index+)
    mon_tran.data[index]=index < data_que.size() ? data_que[index] : 0;

In reply to dave_59:

  task data_read(fifo_trans trans);
    fifo_trans mon_tran_r;
	mon_tran_r=fifo_trans::type_id::create("mon_tran_r");
	
 				 while ((vif.tb_mon_re.cb_mon_re.re===1'b1) && (vif.tb_mon_re.cb_mon_re.empty === 1'b0)) begin
				  @(vif.tb_mon_re.cb_mon_re);
					`uvm_info(get_name() ,"READ task of monitor", UVM_LOW)
					data_que.push_back(vif.tb_mon_re.cb_mon_re.dout);
					
					
					
					@(vif.tb_mon_re.cb_mon_re);
					
				 end 	
				  
					`uvm_info(get_name() ,"END OF READ task of monitor ", UVM_LOW)
					
					for ( int index=0 ; index < trans.data.size()  ; index++) // gives fatal for bad handle of refenrece
					mon_tran_r.data[index] = data_que[index];
					
					mon_tran_r.flag_empty = vif.tb_mon_re.cb_mon_re.empty ;
					
				    `uvm_info(get_name() ,$psprintf("monitor values READ : %s",mon_tran_r.sprint()), UVM_LOW)
		            ana_port.write(mon_tran_r);
					
 endtask

now in this example trans is the randomized transaction that i get from my transaction , and inside trans , there is data { which is dynamic array } which is
getting randomized . now i want to transfer all the elements of data_que to data {which is other transaction } but the size to be remained as that of randomized
data . i tried what you said but i am getting en fatal error
this task if of monitor4 only which is giving fatal

** Fatal: (SIGSEGV) Bad handle or reference.

Time: 59 ns Iteration: 2 Process: /uvm_pkg::uvm_task_phase::execute/fork#2781(#ublk#26#2781)_fe72e39 File: fifo_monitor4.sv

Fatal error in Function uvm_pkg/uvm_object::sprint at C:/Program Files/Questa/win32/…/verilog_src/uvm-1.0p1/src/base/uvm_object.svh line 901

HDL call sequence:

Stopped at C:/Program Files/Questa/win32/…/verilog_src/uvm-1.0p1/src/base/uvm_object.svh 901 Function uvm_pkg/uvm_object::sprint

called from fifo_monitor4.sv 100 Task top/fifo_monitor::data_read

called from fifo_monitor4.sv 48 Task top/fifo_monitor::run_phase

called from C:/Program Files/Questa/win32/…/verilog_src/uvm-1.0p1/src/base/uvm_phases.svh 583 Task uvm_pkg/uvm_run_phase::exec_task

called from C:/Program Files/Questa/win32/…/verilog_src/uvm-1.0p1/src/base/uvm_phases.svh 2788 Function uvm_pkg/uvm_task_phase::execute

In reply to mittal:

i got how to do it , thanks but my problem is still not solved