Systemverilog动态数组
A dynamic array is one dimension of an unpacked array whose size can be set or changed at run-time. Dynamic array is Declared using an empty word subscript [ ].
The space for a dynamic array doesn’t exist until the array is explicitly created at run-time, space is allocated when new[number] is called. the number indicates the number of space/elements to be allocated.
一、Dynamic array Syntax
//data_type is the data type of the array elements.
data_type array_name [ ];
二、Dynamic array methods
- new[ ] –> allocates the storage.
- size( ) –> returns the current size of a dynamic array.
- delete( ) –> empties the array, resulting in a zero-sized array.
2.1 Example:
//declaration
bit [7:0] d_array1[ ];
int d_array2[ ];
//memory allocation
d_array1 = new[4]; //dynamic array of 4 elements
d_array2 = new[6]; //dynamic array of 6 elements
//array initialization
d_array1 = {0,1,2,3};
foreach(d_array2[j]) d_array2[j] = j;
2.2 resize the dynamic array
//Change t