Multi-dimensional dynamic arrays

I know this isn’t directly related to the OVM, but I’ve looked through the SystemVerilog LRM and searched the internet and haven’t been able to find an answer or example, so I figured it was worth a post. :)

Are multi-dimensional dynamic arrays allowed in SystemVerilog? And if so, how does one go about allocating them with new[]?

This is illegal…

int data[][][];
....
c = 5;
a = 10;
v = 2;
data       = new[c];
data[]     = new[a];
data[][]   = new[v];

As is this, obviously…

data = new[c][a][v];

I was hoping there’d be an easy way to do it on one or two lines. The only thing I haven’t tried is to use a few nested foreach loops and declare each dimension iteratively. Anyone know how to accomplish this?
-gb

SystemVerilog allows declarations of arrays of arrays, but the new operator for a dynamic array only allows construction of one array at a time. The only way to create a multidimensional dynamic array in one statement is to use an assignment pattern:

data = '{5{ '{10{ '{2{0}} }} }};

To use new, you need to loop through each dimension

data = new[c];
foreach (data[ii]) begin
  data[ii] = new[a];
  foreach(data[ii][jj]) begin
    data[ii][jj] = new[v];
    end
  end

Note that that dynamic arrays can be irregular. Do a search for irregular arrays in Java.

Dave Rich