關於各種變數的比較

想請問各位大大,以下3種是傳遞值的方式(如下圖)

![](upload://jqFVJocGq10wEkhMSfYw4Fr8TG6.jpeg)

想問說,用哪一種會比較好,因為local variable可以用reference的方式去顯現,只是雖然意思結果一樣但是哪一種對程式比較好,就我所知local variable會去佔電腦的記憶體,而reference我就不太清楚了,只是看人家常用reference去取代local variable,所以想請各位大大為小弟解惑比較一下,謝謝各位大大。

 

根據這裡「http://lavag.org/topic/11108-diffrent-of-property-value-and-local-variable/」的文章,提到:「<span =“apple-style-span” style="color: rgb(28, 40, 55); font-family: arial, verdana, tahoma, sans-serif; line-height: 19px; ">Functionally, they are the same. But the implementation is totally different. A property node will force the front panel to draw and will really slow down your program. Local Variable is faster, but not nearly as fast as a wire, shift register, or terminal.」


就是使用local variable會比使用property node節省資源。因為property node會迫使front panle改變數值,即包含front panel的動作。而local variable則沒有。所以效率:local variable > property node

而根據這裡「http://www.baisi.net/thread-783764-1-139.html」的文章,提到「<span =“apple-style-span” style="border-collapse: collapse; font-family: tahoma, verdana; font-size: 14px; line-height: 25px; ">local variable 每讀寫一次就佔用一塊內存,就是說讀寫次數越多佔用內存越多. <span =“apple-style-span” style="border-collapse: collapse; font-family: tahoma, verdana; font-size: 14px; line-height: 25px; ">而reference相當與c語言裡的地址,是一個變量的標識,對於reference操作就相當於對變量本身操作,reference結合property節點同樣可以對變量進行讀取。 效率應該高些!」。


結合上面兩篇文章,我相信效率是:reference > local variable > property node

耗不資源要如何測我不知道,但是效率(小弟認為執行時間短較有效率)是local variable >> reference > property node.

![](upload://nXxUqQLa8gC5mcJVTgeYe9DvaQP.jpeg)

DonWang40603.4684722222

記得之前也有相關討論,以DonWang的觀點來看,我測試10次的結果是local variable> property node > reference

![](upload://4JleqPnbbMtxhWSYXPjECoIZYRA.jpeg)

我的系統

![](upload://hUfRlUArF4vsjaaJAYsvfsfOCn6.jpeg)

compare local variable_reference_property node.vi