Verification Methodology Forum - Powered by vBulletin
+ Reply to Thread
Results 1 to 2 of 2

Thread: Difference Between Associative and Dynamic Array

  1. #1

    Question Difference Between Associative and Dynamic Array

    Hi All,

    Can any body tell me the

    Difference between Associative and Dynamic Array.

    Regards

    Kunal Mishra

  2. #2
    Join Date
    Jan 2008
    Location
    Portland, OR, USA
    Posts
    156

    Default

    With a regular array, you must specify its size when you declare it

    Code:
    bit my_array[10];
    With a dynamic array you can allocate the size of the array during runtime (hence the term "dynamic").

    Code:
    bit my_dynamic_array[];  // Note size is not specified
    
    ...
    
    my_dynamic_array = new[size];  // size is determined at run-time
    Also, the array can be "re-sized" at a later point:

    Code:
    my_dynamic_array = new[new_size](my_dynamic_array);
    In this case, new memory is allocated, and the old array values are copied into the new memory, giving the effect of resizing the array.

    The main characteristic of an associative array is that the index type can be any type - you are not restricted to just integer values. For example, you can use a string as the index to look up an "associated" value.

    Code:
    bit my_assoc_array[string];  // Array stores bits, using a string as an index
    ...
    my_assoc_array["testname"] = 1;  //Stores a 1 into the array element indexed by the value "testname"
    $display(my_assoc_array["testname"]); // Displays 1

    An associative array is also "dynamic", in the sense that it does not have a pre-determined size. However, you do not have to allocate the size - it grows as you add more elements into it.

    Regards,
    -Kurt
    Kurt Schwartz
    Willamette HDL, Inc.
    Experts in SystemVerilog and OVM Training
    www.whdl.com

+ Reply to Thread

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts