I only have a little coding experience in C, and I remember I was told that pass by reference is more efficient than pass by value since the parameters don't need to be copied. Since there is no pass by reference in Mathematica, I'm wondering if that affects the performance of function calls, especially when dealing with large data?
1 Answer
$\begingroup$
$\endgroup$
1
In Mathematica, this does not affect performance because copying does not take place most of the time. To put it simply, Mathematica implements copy-on-demand: it creates a copy of the data structure only if it is modified. Please see this answer for a more detailed explanation:
Does passing a variable with a large amount of data cost a lot of memory and time in Mathematica?
-
6$\begingroup$ I think @Nasser makes a valid point. When one needs to modify something inside a function, passing symbol (variable) where that something is stored, by reference, greatly reduces the overhead of modification, since it is done in place. I actually also felt that this is worth mentioning back then, see my last comment to your answer on SO. $\endgroup$ Commented Mar 8, 2013 at 2:19
Unevaluated
, which is a wrong thing to do from the software development perspective. Instead,Hold
- attributes should be used, as I emphasized in my answer there, and then also here. $\endgroup$