Object in a dynamic array shows up as null after begin newed

I understand that one has to proceed with caution while dealing with randomizing a dynamic array of objects.

I have the following : I am trying to randomize the blah_cfg ( which is a dynamic array). In the post_randomize() function, I did new the first dimension before iteratively newing the 2nd dimension of the array. But I still get the message that the objects have not been newe’d ( and that they are null). What am I doing wrong ?

class foo_bar_car extends foo_bar_cfg;
  `uvm_object_utils(foo_bar_car)

  // var : blah_cfg
  // This holds the info on all the slots for this node. Its indexed
  // by slice and the slot number
  rand foo_bar_blah_cfg blah_cfg[][];

  // func : new
  function new(string name = "foo_bar_car");
    super.new(name);
  endfunction // new

  // func: post_randomize()
  function void post_randomize();
    blah_cfg = new[10];
    foreach (blah_cfg[ii]) begin
      blah_cfg[ii] = new[10];
      `LUVM_INFO("DBG", $sformatf("Num Dims:%0d", ii));
    end

    foreach (blah_cfg[ii]) begin
      foreach(blah_cfg[ii][jj]) begin
        if (blah_cfg[ii][jj] == null) begin
          `LUVM_INFO("DBG", $sformatf("X:%0d Y:%0d is NULL", ii, jj));--> For the entire 10x10 array, this message is printed.
        end
        else begin
          `LUVM_INFO("DBG", $sformatf("X:%0d Y:%0d is NOT NULL", ii, jj)); 
        end
      end
    end

  endfunction // post_randomize

endclass // foo_bar_car  

In reply to DVJoe:

The dynamic array new[N], with square brackets is different from calling a class constructor new(). When constructing a dynamic array dimension, you are just allocating a set of variables. The first statement
blah_cfg = new[10];
constructs an array of 10 empty dynamic arrays. The statement
blah_cfg[ii] = new[10];
inside the foreach loop construct 10 dynamic arrays, each with 10 elements. And each element is a class variable that initially has a null handle. Your code never constructs any class objects. You can do that with

    foreach (blah_cfg[ii]) begin
      blah_cfg[ii] = new[10];
      `LUVM_INFO("DBG", $sformatf("Num Dims:%0d", ii));
   end
   foreach (blah_cfg[ii,jj]) blah_cfg[ii][jj] = new;

Also, you most likely want to do this in the pre_randomize method, not the post.

In reply to dave_59:

Thanks Dave. You are right! Last night after I posted this message on the forum, I started adding checks to see if the object was null ( after I thought they had been created) and sure enough they were all null which made me realize that I had not created the object at all.

It was then that I came across this -

https://verificationacademy.com/forums/systemverilog/randomizing-dynamic-array-size

Where you talked about needing to “actually” newing the object (rather than simply allocating it)

Thank you! I also moved it to the pre_randomize() too!