使用Globals而不是在Matlab中传递大数组 [英] Using Globals instead of passing large arrays in Matlab

查看:179
本文介绍了使用Globals而不是在Matlab中传递大数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用大型数组(每个大约70 MB),并担心将它们传递给函数。我的理解是Matlab使用传值函数参数,为被调用的函数制作本地副本。

作为一个肮脏的解决方法,我已经将大数组声明为全局,并在计算完成时手动解除分配。

我的问题:
有没有一种方法可以在Matlab中使用指针?这是我将如何在C / C ++中完成的。如果没有,是否还有其他更有效的内存方法?我读过全球通常是一个坏主意。

解决方案

@mutzmatron在评论中回答了我的问题,所以这是一个

实际上,Matlab通过引用传递,除非它确定它需要传递值...请参阅此处的解释:
http://www.mathworks.com/matlabcentral/answers/ ...

a>


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆