SystemVerilog queue vs dynamic array

Choose between SystemVerilog queues and dynamic arrays by comparing resizing, insertion, deletion, access and performance intent.

Dynamic array

A dynamic array has a runtime-selected size but contiguous indexed storage. Allocate or resize it explicitly with new[size].

int samples[];
samples = new[16];
samples = new[32](samples); // resize and retain existing elements

Use a dynamic array when the collection size changes occasionally and most work is indexed traversal or bulk processing. Deleting it with samples.delete() returns its size to zero.

Queue

A queue grows and shrinks automatically and supports efficient operations at its ends.

int pending[$];
pending.push_back(10);
pending.push_front(5);
int next = pending.pop_front();

Use a queue for ordered transactions, expected-result scoreboards and work lists. A bounded queue such as int pending[$:15] limits the highest index but does not block when full; code must still check the policy required by the testbench.

Selection guide

Choose a dynamic array when you know the required size at an allocation point, need array-style data transfer, or want to model a variable-sized memory image. Choose a queue when elements arrive and leave over time or when insertion and removal are central operations.

Both support indexing, foreach and many array methods. Neither is automatically thread-safe. If multiple processes share the collection, coordinate access with a semaphore, mailbox or a single owning process. Avoid repeatedly inserting at the front of a large dynamic array because it requires manual resizing and copying.

Continue into the complete lesson

Use the course lesson for the surrounding design rules, exercises, labs and knowledge check.

Open supporting lesson →
Related answers

Continue exploring this topic

SystemVerilog constraint examples

Use SystemVerilog inside, dist, implication, solve-before, soft and foreach constraints with practical examples and debugging guidance.