使用Globals而不是在Matlab中传递大数组 [英] Using Globals instead of passing large arrays in Matlab
问题描述
作为一个肮脏的解决方法,我已经将大数组声明为全局,并在计算完成时手动解除分配。
我的问题:
有没有一种方法可以在Matlab中使用指针?这是我将如何在C / C ++中完成的。如果没有,是否还有其他更有效的内存方法?我读过全球通常是一个坏主意。
@mutzmatron在评论中回答了我的问题,所以这是一个
实际上,Matlab通过引用传递,除非它确定它需要传递值...请参阅此处的解释:
http://www.mathworks.com/matlabcentral/answers/ ...
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.
@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/...
这篇关于使用Globals而不是在Matlab中传递大数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!