<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237081</link>
    <title>MATLAB Central Newsreader - explicitly pass parameter by reference</title>
    <description>Feed for thread: explicitly pass parameter by reference</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 06 Oct 2008 16:20:21 -0400</pubDate>
      <title>explicitly pass parameter by reference</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237081#603931</link>
      <author>Young Zhou</author>
      <description>I want to know how to pass parameters by reference? I need to pass and big chunk of data to a function, and this function does not change data.&lt;br&gt;
&lt;br&gt;
I found an article (&lt;a href=&quot;http://www.mathworks.com/support/solutions/data/1-15SO4.html?solution=1-15SO4)&quot;&gt;http://www.mathworks.com/support/solutions/data/1-15SO4.html?solution=1-15SO4)&lt;/a&gt; which states that Matlab will determine whether to pass by value or pass by reference automatically. I just want to confirm it.</description>
    </item>
    <item>
      <pubDate>Mon, 06 Oct 2008 17:07:26 -0400</pubDate>
      <title>Re: explicitly pass parameter by reference</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/237081#603951</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;Young Zhou&quot; &amp;lt;predicate_zy@yahoo.com&amp;gt; wrote in message &lt;br&gt;
news:gcdds5$o8j$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;I want to know how to pass parameters by reference? I need to pass and big &lt;br&gt;
&amp;gt;chunk of data to a function, and this function does not change data.&lt;br&gt;
&lt;br&gt;
You cannot, unless your parameter is an instance of a handle class.&lt;br&gt;
&lt;br&gt;
&amp;gt; I found an article &lt;br&gt;
&amp;gt; (&lt;a href=&quot;http://www.mathworks.com/support/solutions/data/1-15SO4.html?solution=1-15SO4)&quot;&gt;http://www.mathworks.com/support/solutions/data/1-15SO4.html?solution=1-15SO4)&lt;/a&gt; &lt;br&gt;
&amp;gt; which states that Matlab will determine whether to pass by value or pass &lt;br&gt;
&amp;gt; by reference automatically. I just want to confirm it.&lt;br&gt;
&lt;br&gt;
MATLAB uses copy-on-write, which means that if you don't change the data &lt;br&gt;
inside your function, it will not be copied into the workspace of the &lt;br&gt;
function.  For instance, in:&lt;br&gt;
&lt;br&gt;
function y = myfunction(x)&lt;br&gt;
y = x(1);&lt;br&gt;
&lt;br&gt;
you're not writing to x, so even if x is very large it won't be copied into &lt;br&gt;
the workspace.  You can see this:&lt;br&gt;
&lt;br&gt;
% open whatever memory profiling tool you want&lt;br&gt;
% on Windows, you can use Task Manager.&lt;br&gt;
% on other platforms, you can use &quot;top&quot;&lt;br&gt;
% When you execute this command, the memory usage of MATLAB should increase &lt;br&gt;
significantly&lt;br&gt;
x = ones(10000);&lt;br&gt;
% When you execute this command, it shouldn't.&lt;br&gt;
y = myfunction(x);&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com </description>
    </item>
  </channel>
</rss>

