Dynamic Arrays in System Verilog

Arrays :

                       1. size( )

                       2. delete( )

                                    1.size( )

                                   2. delete( ) & delete(index)

                                   3. insert(  )

                                   4. push( ) methods

                                   5. pop( ) methods

                                   1.size( )

                                   2.delete ( ) & delete(index)

                                  3.num ( )

                                  4.exists( )

                                  5.first( ) ,next( ), prev ( ), last( )

Common  Methods for Dynamic Arrays & Queues :

                                                     Dynamic Arrays

What  is  a Dynamic array?

           Dynamic array is a type of array where we can allocate memory for the array during runtime. It is a one dimensional unpacked array .  The size of the array can be allocated or deallocated as per our requirement . We can use dynamic arrays where the size of the collection of data is not known.

Syntax : 

      data_type  variable_name[   ];

Example : 

       int  xtn[  ];   

       bit   [3:0]mem[  ];  // n locations and each location is of 4 bits size

           In the above example ,open braces are mentioned after the variable name indicating that it is one 

           dimension unpacked array with dynamic array functionality.

        –> The size of an array can be allocated using “new[  ]” method . For example if we pass 5 as 

              argument in the new[ ] method (i.e new[ 5 ]),it will allocates 5 locations of memory during runtime.

        –> Dynamic arrays won’t have fixed size like static arrays. Size can be varied during runtime.

     Animated Video Example

 

Simulated_Example:

 module dynami_array();

             int array_1[ ];

             bit [3:0] array_2 [ ];

             initial

               begin

                array_1= new [5];

                array_2 = new[5];

                for(int i=0; i<5 ; i=i+1)

                  begin

                    array_1[i] = i;

                    array_2[i] = i+5;

                  end         

               $display(“values of array are as follows”);

               $display(” %p “,array_1);

               $display(” %p “,array_2);

               $display(” %b “,array_2[0]);

            end

   endmodule

 

 

 

 

 

Simulator_output

    *******************************************************************

     values of array are as follows

     ‘{0, 1, 2, 3, 4} 

     ‘{‘h5, ‘h6, ‘h7, ‘h8, ‘h9}           // output for printing complete array using %P

     0101                             // output for printing each scalar of an array with %b

     ******************************************************************