When the size of the collection is unknown or the data space is sparse, an associative array is used, which does not have any storage allocated until it is used. That means, it is dynamically allocated, but has non-contiguous elements. Associative array’s index expression is not restricted to integral expressions, but can be of any type.
Practical Example
RAM(RANDOM ACCESS MEMORY)
in RAM ,huge amount of data needs to be accessed , why do you want to declare the size in compile time, so it is declared as associative array
Building uvm config using associative array
to build UVM config DB feature , you wanted something which can accessible from any where with any type ..
See below code for implementation of UVM confib db
// This class is generated using static method and use of associative array !
uvm_config_db::set and uvm_config_db::get methods are used to store and retrive the information from database respectively.
class uvm_type_of_config_db #( type T =int)
static T db[string]; // static associative array
static function void set(input string name, input T value)
db[name]= value;
endfunction
static function void get(input string name , ref T value);
value= db[name];
endfunction
static function void print();
$display(“Configuration databse %s”, $typename(T));
foreach(db[i])
$diaplay(“db[%s} =%p”,i,db[i]);
endfunction
endclass
We will see example here , how do we use above class
class Dv_testing;
int i,j;
endclass
int i=2;
int val;
real pi=3.14;
Dv_testing dv;
initial begin
//calling set method
uvm_type_of_config_db#(int)::set(“i”,i);
uvm_type_of_config_db#(real)::set(“pi,pi);
dv=new()
dv.i=8;
dv.j=6;
uvm_type_of_config_db#(Dv_testing)::set(“dv”,dv);
//calling get method
uvm_type_of_config_db#(int)::get(“i”,val);
$display(“Value get return of i is %0d”,k); // val value is 2
uvm_type_of_config_db#(int)::print();
uvm_type_of_config_db#(real)::print();
uvm_type_of_config_db#(Dv_testing)::print();
end