I have a small code as below.I am expecting the size of the associative array to be ‘10’. But it is only ‘1’. Why are the values being overwritten?.
What should be changed to get the size of load_array to be ‘10’.
I’m actually using similar logic in a UVM class method.(write method of analysis port).I’m seeing the same issue there. So, reproduced it in systemverilog for better understanding. Is it because, we are passing all the values at the same simulation time?
program my;
initial begin
for(int i=10;i<20;i++)begin
load_array(i);
end
end
function automatic load_array(int my_int);
bit assoc_arr[int];
assoc_arr[my_int]=1;
$display("size of assoc_array=%0d",assoc_arr.size());
foreach(assoc_arr[i]) $display("assoc_arr[%0d]=%0d",i,assoc_arr[i]);
endfunction
endprogram