I am having a class packet with a dynamic array. I would like to know if the new / randomize function of the class object can allocate memory for the dynamic array.
class packet;
rand int data[];
constraint c_data_size { data.size == 2; };
endclass : packet
program test;
packet pk1;
pk1 = new();
$display(" data.size = %d", data.size);
if(pk1.randomize) begin
$display(" data.size = %d", data.size);
data[0] = 23;
data[1] = 23432;
end
endprogram
Output
data.size = 0
data.size = 2
From this example code, I understand that new() function does not allocate memory for dynamic array data[] but can randomize allocate memory for data[] as I have not called "data = new[2];" on dynamic array. Thanks for your time.