Part 1 · Language Foundations · Intermediate
Arrays: Packed, Dynamic, Queues & Associative
Hub — packed vs unpacked layout, dynamic arrays, queues, associative arrays, built-in methods, and choosing the right container.
Overview
SystemVerilog gives you four fundamentally different array families, and picking the wrong one is one of the most common sources of slow testbenches and synthesis surprises. Packed arrays are contiguous bit vectors the simulator treats as a single value; unpacked fixed-size arrays are collections of independent elements; dynamic arrays and queues grow at runtime; and associative arrays are sparse hash maps indexed by any type. Each has different memory cost, access semantics, and method support.
This topic matters far beyond syntax. Interviewers routinely ask candidates to compare the four families, to model a sparse 4 GB memory without allocating 4 GB, or to build a scoreboard expected-queue — all of which hinge on choosing the right array. Synthesis tools only accept fixed-size arrays, so knowing where the dynamic families are legal (testbench, class-based code) is part of writing code that actually compiles for the target.
Sub-topics
Packed vs Unpacked Arrays — memory layout, range syntax, multidimensional declarations, slicing, synthesis rules.
Dynamic Arrays — new[n] allocation, resize that preserves contents, copy semantics, delete().
Queues — push/pop at both ends, insert/delete, $-slicing, bounded queues, scoreboard FIFOs.
Associative Arrays — index types, exists/delete/num, first/next iteration, sparse memory models.
Array Reduction & Locator Methods — sum/min/max, find with clauses, sort/unique, queue-returning locators.
Choosing the Right Array Type — decision matrix, performance and memory trade-offs, interview comparison.
SYSTEMVERILOG ARRAY FAMILIES — TOPIC MAP
┌────────────────────────────────────────────────────────────┐
│ SystemVerilog arrays │
└──────────────┬─────────────────────────────┬───────────────┘
│ │
size fixed at compile size set at runtime
│ │
┌─────────┴─────────┐ ┌──────────┼─────────────┐
▼ ▼ ▼ ▼ ▼
┌─────────┐ ┌──────────┐ ┌────────┐ ┌───────┐ ┌────────────┐
│ packed │ │ unpacked │ │dynamic │ │ queue │ │associative │
│ [7:0] a │ │ a [0:7] │ │ a[] │ │ a[$] │ │ a[KEY_T] │
└────┬────┘ └────┬─────┘ └───┬────┘ └───┬───┘ └─────┬──────┘
│ │ │ │ │
one vector, N independent new[n] push/pop sparse hash,
bit-sliceable elements resize both ends any index type
synthesizable synthesizable TB only TB only TB only
│ │ │ │ │
└──────────────────┴─────┬─────┴──────────┴───────────┘
▼
built-in methods: sum, min, max,
find/find_index, sort, unique ...Key takeaways
Packed = single bit vector; unpacked = collection of elements — different layout, different operations.
Dynamic arrays, queues, and associative arrays are runtime containers — testbench only, never synthesis.
Built-in reduction and locator methods replace hand-written loops across all unpacked families.
Choosing the right family is a stock interview question — know the comparison cold.