<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/125792</link>
    <title>MATLAB Central Newsreader - Pass by Reference?</title>
    <description>Feed for thread: Pass 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>Thu, 01 Jun 2006 16:14:57 -0400</pubDate>
      <title>Pass by Reference?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/125792#316802</link>
      <author>Brandon Aubie</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
Is there a &quot;proper&quot; way to pass objects by reference? We need to&lt;br&gt;
pass a large object around NUMEROUS times (ie, &amp;gt;10000) and it's&lt;br&gt;
very slow. Passing by reference would speed this up tremendously.&lt;br&gt;
&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Thu, 01 Jun 2006 17:20:58 -0400</pubDate>
      <title>Re: Pass by Reference?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/125792#316814</link>
      <author>Peter Boettcher</author>
      <description>&quot;Brandon Aubie&quot; &amp;lt;brandon.aubie@TAKETHISOUTelecore.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Is there a &quot;proper&quot; way to pass objects by reference? We need to&lt;br&gt;
&amp;gt; pass a large object around NUMEROUS times (ie, &amp;gt;10000) and it's&lt;br&gt;
&amp;gt; very slow. Passing by reference would speed this up tremendously.&lt;br&gt;
&lt;br&gt;
Simply passing it around (and accessing it) is not slow.  No copy is&lt;br&gt;
done, and pass-by-reference is indeed the internal implementation.  If&lt;br&gt;
you start modifying the object, then the data is copied.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Peter Boettcher &amp;lt;boettcher@ll.mit.edu&amp;gt;&lt;br&gt;
MIT Lincoln Laboratory&lt;br&gt;
MATLAB FAQ: &lt;a href=&quot;http://www.mit.edu/~pwb/cssm/&quot;&gt;http://www.mit.edu/~pwb/cssm/&lt;/a&gt;</description>
    </item>
    <item>
      <pubDate>Thu, 01 Jun 2006 23:36:20 -0400</pubDate>
      <title>Re: Pass by Reference?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/125792#316815</link>
      <author>CRet</author>
      <description>HI,&lt;br&gt;
&lt;br&gt;
As long as you only have one object to pass. Why not simply declare it as&lt;br&gt;
global ?&lt;br&gt;
&lt;br&gt;
I know, global variables are not recommended but it will greatly simplify&lt;br&gt;
argument passing.&lt;br&gt;
This is only a suggestion. I will not be reponsible of any lost of data,&lt;br&gt;
property damage, personal injury, lost of time in development or maintenance&lt;br&gt;
of the code. Even be involve in the future problematic evolution of your&lt;br&gt;
application since I forcast that you will in a close futur have two or three&lt;br&gt;
of this large object to handel simultaneously.&lt;br&gt;
&lt;br&gt;
Remember, integrety of your aobject will be difficult to maintain, since all&lt;br&gt;
functions or scripts  which declare it as global may modify or delete it&lt;br&gt;
expectively or unexpectively. This make sametime debugging really hard for&lt;br&gt;
large project. If you are leading a developer team, be sure co-workers&lt;br&gt;
respect naming rules and access policy to your base workspace and disk paths&lt;br&gt;
!&lt;br&gt;
&lt;br&gt;
If some one here or there ask me if I give you this advice. I will denie. I&lt;br&gt;
will say that I never use any global variable, or I only have one time, a&lt;br&gt;
long time ago, on low RAM system, few disk space networks, no GUI, only&lt;br&gt;
command line intructions setup, on slow micro-WAX machines, reading  large&lt;br&gt;
data set (concept of objects was not establish) from kilometric magnetic&lt;br&gt;
tapes, unsing MATLAB ver2 or 3...&lt;br&gt;
At this time, global variable was the only change we have to run the&lt;br&gt;
project.&lt;br&gt;
&lt;br&gt;
Hope this help.&lt;br&gt;
&lt;br&gt;
C.Ret&lt;br&gt;
&lt;br&gt;
P.S.: &quot;very slow&quot; means how many days of computations ? I remenber that&lt;br&gt;
former project when the first steps to prepare the large data set from raw&lt;br&gt;
acquisitions was about 72h.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If  &quot;very slow&quot; means 1 or 2 mins, there is perhaps no benefit to&lt;br&gt;
investigate time in modifying and debugging your actual code. Think at the&lt;br&gt;
time gained at future evolutions or developments of your already well&lt;br&gt;
structurated data object and code compared to difficult evolution of an&lt;br&gt;
unstructurated code using global workspace.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&quot;Brandon Aubie&quot; &amp;lt;brandon.aubie@TAKETHISOUTelecore.com&amp;gt; wrote in&lt;br&gt;
news:ef386cf.-1@webcrossing.raydaftYaTP...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Is there a &quot;proper&quot; way to pass objects by reference? We need to&lt;br&gt;
&amp;gt; pass a large object around NUMEROUS times (ie, &amp;gt;10000) and it's&lt;br&gt;
&amp;gt; very slow. Passing by reference would speed this up tremendously.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Thanks</description>
    </item>
    <item>
      <pubDate>Fri, 02 Jun 2006 10:20:59 -0400</pubDate>
      <title>Re: Pass by Reference?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/125792#316871</link>
      <author>Michael Salloker</author>
      <description>CRet schrieb:&lt;br&gt;
&amp;gt; HI,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; As long as you only have one object to pass. Why not simply declare it as&lt;br&gt;
&amp;gt; global ?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I know, global variables are not recommended but it will greatly simplify&lt;br&gt;
&amp;gt; argument passing.&lt;br&gt;
&amp;gt; This is only a suggestion. I will not be reponsible of any lost of data,&lt;br&gt;
&amp;gt; property damage, personal injury, lost of time in development or maintenance&lt;br&gt;
&amp;gt; of the code. Even be involve in the future problematic evolution of your&lt;br&gt;
&amp;gt; application since I forcast that you will in a close futur have two or three&lt;br&gt;
&amp;gt; of this large object to handel simultaneously.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Remember, integrety of your aobject will be difficult to maintain, since all&lt;br&gt;
&amp;gt; functions or scripts  which declare it as global may modify or delete it&lt;br&gt;
&amp;gt; expectively or unexpectively. This make sametime debugging really hard for&lt;br&gt;
&amp;gt; large project. If you are leading a developer team, be sure co-workers&lt;br&gt;
&amp;gt; respect naming rules and access policy to your base workspace and disk paths&lt;br&gt;
&amp;gt; !&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If some one here or there ask me if I give you this advice. I will denie. I&lt;br&gt;
&amp;gt; will say that I never use any global variable, or I only have one time, a&lt;br&gt;
&amp;gt; long time ago, on low RAM system, few disk space networks, no GUI, only&lt;br&gt;
&amp;gt; command line intructions setup, on slow micro-WAX machines, reading  large&lt;br&gt;
&amp;gt; data set (concept of objects was not establish) from kilometric magnetic&lt;br&gt;
&amp;gt; tapes, unsing MATLAB ver2 or 3...&lt;br&gt;
&amp;gt; At this time, global variable was the only change we have to run the&lt;br&gt;
&amp;gt; project.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hope this help.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; C.Ret&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; P.S.: &quot;very slow&quot; means how many days of computations ? I remenber that&lt;br&gt;
&amp;gt; former project when the first steps to prepare the large data set from raw&lt;br&gt;
&amp;gt; acquisitions was about 72h.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;     If  &quot;very slow&quot; means 1 or 2 mins, there is perhaps no benefit to&lt;br&gt;
&amp;gt; investigate time in modifying and debugging your actual code. Think at the&lt;br&gt;
&amp;gt; time gained at future evolutions or developments of your already well&lt;br&gt;
&amp;gt; structurated data object and code compared to difficult evolution of an&lt;br&gt;
&amp;gt; unstructurated code using global workspace.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;Brandon Aubie&quot; &amp;lt;brandon.aubie@TAKETHISOUTelecore.com&amp;gt; wrote in&lt;br&gt;
&amp;gt; news:ef386cf.-1@webcrossing.raydaftYaTP...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt;Hi,&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;Is there a &quot;proper&quot; way to pass objects by reference? We need to&lt;br&gt;
&amp;gt;&amp;gt;pass a large object around NUMEROUS times (ie, &amp;gt;10000) and it's&lt;br&gt;
&amp;gt;&amp;gt;very slow. Passing by reference would speed this up tremendously.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;Thanks&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
I would not recommend global variables, the reasons are posted in this &lt;br&gt;
forum often, and are discussed much.&lt;br&gt;
&lt;br&gt;
An alternative approach is the use of nested functions. A nested &lt;br&gt;
function can access the variables of all functions in which it is &lt;br&gt;
nested. So ther is no need to pass any parameter.&lt;br&gt;
&lt;br&gt;
Michael</description>
    </item>
    <item>
      <pubDate>Fri, 02 Jun 2006 07:24:29 -0400</pubDate>
      <title>Re: Pass by Reference?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/125792#316908</link>
      <author>Loren Shure</author>
      <description>Michael Salloker wrote:&lt;br&gt;
&amp;gt; CRet schrieb:&lt;br&gt;
&amp;gt;&amp;gt; HI,&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; As long as you only have one object to pass. Why not simply declare it as&lt;br&gt;
&amp;gt;&amp;gt; global ?&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; I know, global variables are not recommended but it will greatly simplify&lt;br&gt;
&amp;gt;&amp;gt; argument passing.&lt;br&gt;
&amp;gt;&amp;gt; This is only a suggestion. I will not be reponsible of any lost of data,&lt;br&gt;
&amp;gt;&amp;gt; property damage, personal injury, lost of time in development or &lt;br&gt;
&amp;gt;&amp;gt; maintenance&lt;br&gt;
&amp;gt;&amp;gt; of the code. Even be involve in the future problematic evolution of your&lt;br&gt;
&amp;gt;&amp;gt; application since I forcast that you will in a close futur have two or &lt;br&gt;
&amp;gt;&amp;gt; three&lt;br&gt;
&amp;gt;&amp;gt; of this large object to handel simultaneously.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Remember, integrety of your aobject will be difficult to maintain, &lt;br&gt;
&amp;gt;&amp;gt; since all&lt;br&gt;
&amp;gt;&amp;gt; functions or scripts  which declare it as global may modify or delete it&lt;br&gt;
&amp;gt;&amp;gt; expectively or unexpectively. This make sametime debugging really hard &lt;br&gt;
&amp;gt;&amp;gt; for&lt;br&gt;
&amp;gt;&amp;gt; large project. If you are leading a developer team, be sure co-workers&lt;br&gt;
&amp;gt;&amp;gt; respect naming rules and access policy to your base workspace and disk &lt;br&gt;
&amp;gt;&amp;gt; paths&lt;br&gt;
&amp;gt;&amp;gt; !&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; If some one here or there ask me if I give you this advice. I will &lt;br&gt;
&amp;gt;&amp;gt; denie. I&lt;br&gt;
&amp;gt;&amp;gt; will say that I never use any global variable, or I only have one time, a&lt;br&gt;
&amp;gt;&amp;gt; long time ago, on low RAM system, few disk space networks, no GUI, only&lt;br&gt;
&amp;gt;&amp;gt; command line intructions setup, on slow micro-WAX machines, reading  &lt;br&gt;
&amp;gt;&amp;gt; large&lt;br&gt;
&amp;gt;&amp;gt; data set (concept of objects was not establish) from kilometric magnetic&lt;br&gt;
&amp;gt;&amp;gt; tapes, unsing MATLAB ver2 or 3...&lt;br&gt;
&amp;gt;&amp;gt; At this time, global variable was the only change we have to run the&lt;br&gt;
&amp;gt;&amp;gt; project.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Hope this help.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; C.Ret&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; P.S.: &quot;very slow&quot; means how many days of computations ? I remenber that&lt;br&gt;
&amp;gt;&amp;gt; former project when the first steps to prepare the large data set from &lt;br&gt;
&amp;gt;&amp;gt; raw&lt;br&gt;
&amp;gt;&amp;gt; acquisitions was about 72h.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;     If  &quot;very slow&quot; means 1 or 2 mins, there is perhaps no benefit to&lt;br&gt;
&amp;gt;&amp;gt; investigate time in modifying and debugging your actual code. Think at &lt;br&gt;
&amp;gt;&amp;gt; the&lt;br&gt;
&amp;gt;&amp;gt; time gained at future evolutions or developments of your already well&lt;br&gt;
&amp;gt;&amp;gt; structurated data object and code compared to difficult evolution of an&lt;br&gt;
&amp;gt;&amp;gt; unstructurated code using global workspace.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; &quot;Brandon Aubie&quot; &amp;lt;brandon.aubie@TAKETHISOUTelecore.com&amp;gt; wrote in&lt;br&gt;
&amp;gt;&amp;gt; news:ef386cf.-1@webcrossing.raydaftYaTP...&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; Hi,&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; Is there a &quot;proper&quot; way to pass objects by reference? We need to&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; pass a large object around NUMEROUS times (ie, &amp;gt;10000) and it's&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; very slow. Passing by reference would speed this up tremendously.&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&amp;gt; Thanks&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I would not recommend global variables, the reasons are posted in this &lt;br&gt;
&amp;gt; forum often, and are discussed much.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; An alternative approach is the use of nested functions. A nested &lt;br&gt;
&amp;gt; function can access the variables of all functions in which it is &lt;br&gt;
&amp;gt; nested. So ther is no need to pass any parameter.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Michael&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
I agree that nested functions might provide a good way to go - depending &lt;br&gt;
on your code base and how many people edit it.  See this post:&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/loren/?p=36&quot;&gt;http://blogs.mathworks.com/loren/?p=36&lt;/a&gt; for more information about how &lt;br&gt;
MATLAB handles variables and uses memory.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
--Loren&lt;br&gt;
&lt;a href=&quot;http://blogs.mathworks.com/loren/&quot;&gt;http://blogs.mathworks.com/loren/&lt;/a&gt;</description>
    </item>
  </channel>
</rss>

