Search code examples
matlabglobal-variablesparameter-passingpass-by-referencelarge-data

Using Globals instead of passing large arrays in Matlab


I am using large arrays (about 70 MB each) and am worried about passing them to functions. My understanding is Matlab uses pass-by-value function arguments, making local copies for the called function.

As a dirty workaround, I've been declaring the large arrays as global, and manually de-allocating them when computations are completed.

My question: Is there a way to use pointers in Matlab? This is how I would do it in C/C++. If not, are there other more memory efficient methods? I've read that globals are generally a bad idea.


Solution

  • @mutzmatron answered my question in a comment, so this is a repost:

    Actually Matlab passes by reference, unless it decides it needs to pass by value...see the explanation here: http://www.mathworks.com/matlabcentral/answers/...