Uvm_pool get() function. Is it broken?

In reply to raysalemi:

In reply to raysalemi:
Right, but this is completely broken for any object and cannot be overridden because of all the static functions.

If you don’t like the fact that it returns a null for objects when trying to read an entry that doesn’t exist, then you can (in theory) extend the class. The pool variables is protected and the get() function is virtual.

The question you get, though, is “how do you construct the objects?”. Classes can have different construct argument signatures, so it’s impossible to build a one-size-fits-all-solution. In UVM you can cheat and implement a variant of your pool for uvm_object and it’s children, because there the constructor argument is fixed:


class uvm_object_pool_that_allocates #(type KEY=int, T=uvm_object) extends uvm_pool #(KEY, T);
  virtual function T get (KEY key);
    if (!pool.exists(key)) begin
      T new_obj = new();  // only works because uvm_objects have optional 'name' argument
      pool[key] = new_obj;
    end
    return pool[key];
  endfunction
endclass

This only works because the UVM macros force you to specify a constructor with the signature:


class some_class extends uvm_object;
  function new(string name = "<default_value>");
  // ...
endclass

If you work with classes that have mandatory constructor arguments, then it all blows up.