mpeer Posted April 8, 2011 Report Share Posted April 8, 2011 Hi All, I tried using uvm_pool in my environment. Class: uvm_pool Below is the code in uvm package uvm-1.0-p1: // Function: get // // Returns the item with the given ~key~. // // If no item exists by that key, a new item is created with that key // and returned. virtual function T get (KEY key); if (!pool.exists(key)) begin T default_value; pool[key] = default_value; end return pool[key]; endfunction In above code, default_value is added to the pool without making it new() (Bold lines above). As per the comments, I am expecting non-null item even if it does not exist in the pool. If the above code is written with the intention of having global pool which can have only the existing objects(non-null) then the above written comments for the function must be changed. Code Should be like: // Function: get // // Returns the item with the given ~key~. // // If no item exists by that key, a new item is created with that key // and returned. virtual function T get (KEY key); if (!pool.exists(key)) begin T default_value; default_value = new(); pool[key] = default_value; end return pool[key]; endfunction Please let me know if it is a bug? Thanks and Regards Peer Mohammed Quote Link to comment Share on other sites More sharing options...
jadec Posted April 8, 2011 Report Share Posted April 8, 2011 The type "T" in uvm_pool can be a primitive type (like int or string) where "new()" would not be valid. If you give some example of how you're using uvm_pool, there may be a better mechanism for class objects. Quote Link to comment Share on other sites More sharing options...
mpeer Posted April 8, 2011 Author Report Share Posted April 8, 2011 Hi, In my example I am using uvm_pool as a pool of type uvm_event (similar to ovm_event_pool as in OVM). In OVM also, If no event exists by that name, a new event is created with that name and returned. Please refer to OVM code. I am expecting the similar code in UVM. Otherwise we must change the comment for the "get" function and must have to new() our item then add to the pool before using it(Other Way to achieve the same functionality). Regards Peer Mohammed Quote Link to comment Share on other sites More sharing options...
jadec Posted April 8, 2011 Report Share Posted April 8, 2011 Does uvm_event_pool (a typedef in uvm_pool.svh) do what you expect? Quote Link to comment Share on other sites More sharing options...
mpeer Posted April 12, 2011 Author Report Share Posted April 12, 2011 Finally... That is not a bug. The default entry for an object is ‘null’. The comment “a new item is created with that key” refers to the pool entry, not the object in the pool. Regards, Peer Mohammed Quote Link to comment Share on other sites More sharing options...
Erling Posted July 7, 2011 Report Share Posted July 7, 2011 Finally... That is not a bug. The default entry for an object is ‘null’. The comment “a new item is created with that key†refers to the pool entry, not the object in the pool. Are you sure this isn't a bug? The comment says that the item is the thing that is being returned, and a new item will be created if no item exists by the given key. A null item isn't a created item. Also, OVM and UVMea did what the comment said. It seems the problem new() not working with built-in types is an oversight in the language, i.e it should have been possible to say int i = new(), similar to C++ where int i() means int i=0 (to solve the same problem, I guess). Regards, Erling Quote Link to comment Share on other sites More sharing options...
janick Posted July 7, 2011 Report Share Posted July 7, 2011 It is indeed not a bug. The pool entry is the item that is created. A 'null' value is a valid value for a class reference. It would not be possible to create a version of uvm_pool that allocates classes by default as it would not work for non-class types nor for classes that require argument values in their constructors. If you need the class to be created if it does not exist, you should test its existence first using pool.exists() and create it as necessary. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.