In reply to nana:
“Before time 0” is informal terminology for the state of the system before any processes created by initial or always blocks have started.
You need to separate the concept of a variable from the contents that it refers to. Dynamic storage is a characteristic of content’s type, not the variable itself. I can declare two types of arrays
typedef int FA_t[5]; // Fixed-sized array
typedef int QA_t[$]; // Dynamically-sized queue
and then use those types to declare static or automatic variables.
module top;
typedef int FA_t[5]; // Fixed-sized array
typedef int QA_t[$]; // Dynamically-sized queue
initial repeat(5) begin :loop
static FA_t st_FA = {0,1,2,3,4};
static QA_t st_QA = {0,1,2,3,4};
automatic FA_t au_FA = {0,1,2,3,4};
automatic QA_t au_QA = {0,1,2,3,4};
st_FA[0]++;
au_FA[0]++;
void' ( st_QA.pop_back() );
void' ( au_QA.pop_back() );
$display("st_FA %p au_FA %p", st_FA, au_FA);
$display("st_QA %p au_QA %p", st_QA, au_QA);
end : loop
initial #1 $display($size(loop.st_FA),, $size(loop.st_QA));
endmodule : top
This displays
# st_FA '{1, 1, 2, 3, 4} au_FA '{1, 1, 2, 3, 4}
# st_QA '{0, 1, 2, 3} au_QA '{0, 1, 2, 3}
# st_FA '{2, 1, 2, 3, 4} au_FA '{1, 1, 2, 3, 4}
# st_QA '{0, 1, 2} au_QA '{0, 1, 2, 3}
# st_FA '{3, 1, 2, 3, 4} au_FA '{1, 1, 2, 3, 4}
# st_QA '{0, 1} au_QA '{0, 1, 2, 3}
# st_FA '{4, 1, 2, 3, 4} au_FA '{1, 1, 2, 3, 4}
# st_QA '{0} au_QA '{0, 1, 2, 3}
# st_FA '{5, 1, 2, 3, 4} au_FA '{1, 1, 2, 3, 4}
# st_QA '{} au_QA '{0, 1, 2, 3}
# 5 0
Note that the static, fixed-sized array element st_FA[0] increments 1,2,3…, but the automatic au_FA[0] stays at 1 because the array variable gets re-allocated and re-initialized each time the begin:loop executes.
Each time through the same loop, one element of the static, dynamically sized array st_QA deallocates. After 5 iterations, there or no elements remaining in the queue, leaving it empty. The variable st_QA still exists. Since static variables permanently exist, they can be references from outside their declared scope, as shown in the second initial block. You cannot do that with automatic variables. In this example the automatic variables au_FA and au_QA no longer exist after the first initial block finishes.
SystemVerilog has arrays of arrays which means you can declare and fixed-sized array of queues, or a queue of fixed-sized arrays. There are other dynamic types such as associative arrays and classes that all can be layered in a declaration. Once you reach a dynamic type element, all of the storage underneath that layer becomes dynamically allocated.