डिफ़ॉल्ट रूप से, SystemVerilog मूल्य द्वारा सरणियों से गुजरता है, पूरे सरणी को कॉपी।
प्रदर्शन कारणों से जब भी संभव हो, संदर्भ द्वारा सरणी को पारित करने की अनुशंसा की जाती है।
- यदि आप अपने फ़ंक्शन को सरणी को संशोधित करना चाहते हैं, तो
ref
का उपयोग करें।
- यदि आप अपने फ़ंक्शन को सरणी पढ़ने के लिए चाहते हैं, तो
const ref
का उपयोग करें।
उदाहरण:
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
उदाहरण EDA पर खेल का मैदान: http://www.edaplayground.com/x/2m9
स्रोत
2014-04-30 18:53:45