System Verilog Dynamic Array Methods
Dynamic Array Methods in System Verilog
Arrays :
1. size( )
2. delete( )
Queues
Bounded Queues
Queues methods
1.size( )
2. delete( ) & delete(index)
3. insert( )
4. push( ) methods
5. pop( ) methods
Associative arrays
Associative array methods
1.size( )
2.delete ( ) & delete(index)
3.num ( )
4.exists( )
5.first( ) ,next( ), prev ( ), last( )
Common Methods for Dynamic Arrays & Queues :
size( ) method in Dynamic Arrays
1.size( ) :
–> The size method is used to know the size of an array.
–>This built-in size( ) method will return the current size of an array.
Syntax : array_name.size( );
Example :
int xtn [ ];
int size_value;
size_value=xtn.size( ) ;
In the above example the the inbuilt size( ) method of dynamic array is called using array_name. It returns the size of an array and the returned value is captured in “size_value”.
Simulated_example :
module tb();
int array[ ];
int size ;
initial
begin
array = new [5];
size = array.size();
for(int i=0 ; i<array.size() ; i=i+1)
begin
array[i] = i;
end
$display(“*****************************************”);
$display(” size of an array = %d “, size);
$display(” values of an array = %p ” , array);
$display(“*****************************************”);
end
endmodule
Simulator_output :
***********************************************************************
size of an array = 5
values of an array = ‘{0, 1, 2, 3, 4}
***********************************************************************