Theo mặc định, SystemVerilog đi mảng theo giá trị, sao chép toàn bộ mảng.
Chúng tôi khuyên bạn nên chuyển mảng theo tham chiếu bất cứ khi nào có thể vì lý do hiệu suất.
- Nếu bạn muốn chức năng sửa đổi mảng, hãy sử dụng
ref
.
- Nếu bạn muốn chức năng đọc mảng, hãy sử dụng
const ref
.
Ví dụ:
function void pass_by_value(int array[5], int queue[$], int assoc[int]);
// Default.
// A copy of the arrays is made in this function
endfunction
function void pass_by_ref(ref int array[5], ref int queue[$],
ref int assoc[int]);
// Original arrays are being referenced
endfunction
function void pass_by_const_ref(const ref int array[5],
const ref int queue[$],
const ref int assoc[int]);
// Original arrays are being referenced
// And they can be read but cannot be modified in this function
endfunction
Ví dụ trên EDA Playground: http://www.edaplayground.com/x/2m9
Nguồn
2014-04-30 18:53:45