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

In reply to dshanley:

Randomization method can not create a dynamic array by it self. Therefore function ‘total_size’ return zero (a default value of int total_size).

A array sql should be created by constraint; sql.size.

A solution

// Purpose: 
// Conclusion:
module top;

  typedef byte sgl_t[][][16];

  // Class
  class myclass;
    rand byte sgl[][][16];
 
    rand byte unsigned payload[];
    rand int  unsigned payload_desc[];

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

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

                           }


    function int total_size(sgl_t x);
           foreach (x[i,]) begin
               total_size += x[i].size();
           end
           return total_size;
    endfunction

    constraint C_PAYLOAD_DISTRIBUTION {
        solve sgl before payload_desc;
        payload_desc.size == total_size(sgl);
        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;