RTL Studio Open IDE

Wiki SystemVerilog Dynamic arrays

Dynamic arrays

Runtime-sized arrays with new[] for testbench buffers.

A dynamic array has an empty [] dimension. Size it at runtime with new[n]. Packed DUT memories stay fixed-width; dynamic arrays belong in verification.

flowchart LR
  empty["int q[]"] --> neu["new[n]"]
  neu --> filled[sized_array]
int payload[];
payload = new[8];
payload[0] = 1;
payload = new[payload.size() + 1](payload);  // grow, copy

size() reports the current length. delete() clears it. Do not use dynamic arrays as synthesizable RAM — use packed arrays or inferred SRAM.

Wrong vs right

Wrong — logic [7:0] mem[]; as a DUT storage element for synthesis.

Right — logic [7:0] mem [0:255]; in RTL; byte q[]; in the TB.

See also