How to determine the size of a multi-dimensional dynamic array in a constraint?

In reply to prashant.kaushik:

try the following with the tmpArr and without using any function ‘total_size’ also…
then, it seems to be working fine…

module top;

typedef byte sgl_t[16];

// Class
class myclass;
rand byte sgl[16];

rand byte unsigned payload[];
rand int  unsigned payload_desc[];

rand int tmpArr[];

// Array creation
constraint c_sgl_size {  sgl.size == 5;
                         payload.size == 15;
                        **tmpArr.size == sgl.size;**

                         foreach(sgl[i])  {
                           sgl[i].size == 2;
                        **tmpArr[i] == sgl[i].size;**
                         }

                       }


constraint C_PAYLOAD_DISTRIBUTION {
    solve sgl before payload_desc;
  **payload_desc.size == tmpArr.sum with (int'(item));**
    payload_desc.sum with (longint'(item)) == payload.size;
}

function void post_randomize();

  $display("payload_desc size = %d ", payload_desc.size());

  $display("sgl size = %d ", sgl.size());
  foreach(sgl[i,]) begin
    $display("sgl[%1d].size= %d ", i, sgl[i].size);
  end

  foreach(payload_desc[i]) begin
    $display("payload_desc[%1d]= %d ", i, payload_desc[i]);
  end
endfunction: post_randomize

endclass // myclass

initial
begin
myclass c;

c= new();
if(!c.randomize()) begin
  $display("Randomize fail ");
end
else begin
  $display("Randomize Pass");
end

end
endmodule // top;