<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265312</link>
    <title>MATLAB Central Newsreader - C S Function Rwork vs Global Variables</title>
    <description>Feed for thread: C S Function Rwork vs Global Variables</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>Sun, 08 Nov 2009 21:56:02 -0500</pubDate>
      <title>C S Function Rwork vs Global Variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265312#693077</link>
      <author>Jonathan Currie</author>
      <description>I am currently working on a C s function that uses considerable memory (10000+ doubles) for storing intermediate calculations. I am interested in optimizing the memory usage &amp; runtime performance for both simulations and real time workshop code generation.&lt;br&gt;
&lt;br&gt;
In my experience, I have three resonable options available:&lt;br&gt;
&lt;br&gt;
1) Create one long Rwork vector, and index the addresses to each of the local variables I use at every function call.&lt;br&gt;
&lt;br&gt;
2) Declare a global pointer, and use malloc to fill this with the required memory during initialization. Then index my variables as above.&lt;br&gt;
&lt;br&gt;
3) Declare multiple global pointers, with multiple calls to malloc for each variable during initialization. This means I do not have to index my variables, but multiple malloc calls is also not suggeted.&lt;br&gt;
&lt;br&gt;
If anyone has any suggestions for the best strategy, this would be appreciated!</description>
    </item>
    <item>
      <pubDate>Sun, 08 Nov 2009 23:35:54 -0500</pubDate>
      <title>Re: C S Function Rwork vs Global Variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265312#693097</link>
      <author>Praetorian</author>
      <description>On Nov 8, 2:56&#160;pm, &quot;Jonathan Currie&quot; &amp;lt;jonathan.cur...@hotmail.com&amp;gt;&lt;br&gt;
wrote:&lt;br&gt;
&amp;gt; I am currently working on a C s function that uses considerable memory (10000+ doubles) for storing intermediate calculations. I am interested in optimizing the memory usage &amp; runtime performance for both simulations and real time workshop code generation.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; In my experience, I have three resonable options available:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 1) Create one long Rwork vector, and index the addresses to each of the local variables I use at every function call.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 2) Declare a global pointer, and use malloc to fill this with the required memory during initialization. Then index my variables as above.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 3) Declare multiple global pointers, with multiple calls to malloc for each variable during initialization. This means I do not have to index my variables, but multiple malloc calls is also not suggeted.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; If anyone has any suggestions for the best strategy, this would be appreciated!&lt;br&gt;
&lt;br&gt;
I'd recommend the first strategy. If you plan on having more than one&lt;br&gt;
instance of this S-Function in your model, and if these intermediate&lt;br&gt;
values need to be different for each instance, the global variable&lt;br&gt;
strategy will fail since global variables are common to all S-Function&lt;br&gt;
instances.&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
Ashish.</description>
    </item>
    <item>
      <pubDate>Tue, 10 Nov 2009 21:10:30 -0500</pubDate>
      <title>Re: C S Function Rwork vs Global Variables</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/265312#693646</link>
      <author>Ralph Schleicher</author>
      <description>Praetorian &amp;lt;ashish.sadanandan@gmail.com&amp;gt; writes:&lt;br&gt;
&lt;br&gt;
&amp;gt; I'd recommend the first strategy. If you plan on having more than one&lt;br&gt;
&amp;gt; instance of this S-Function in your model, and if these intermediate&lt;br&gt;
&amp;gt; values need to be different for each instance, the global variable&lt;br&gt;
&amp;gt; strategy will fail since global variables are common to all S-Function&lt;br&gt;
&amp;gt; instances.&lt;br&gt;
&lt;br&gt;
Simplicity in the implementation rules, therefore use strategy 3).&lt;br&gt;
Multiple pointers don't use that much more memory than one single&lt;br&gt;
pointer.  And 10000 doubles are 80 kiB, that means approx. 13500&lt;br&gt;
instances of your S-function fit into 1 GiB.  Think about that.&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Ralph Schleicher  &amp;lt;&lt;a href=&quot;http://ralph-schleicher.de&quot;&gt;http://ralph-schleicher.de&lt;/a&gt;&amp;gt;&lt;br&gt;
&lt;br&gt;
Development * Consulting * Training&lt;br&gt;
Mathematical Modeling and Simulation&lt;br&gt;
Software Tools</description>
    </item>
  </channel>
</rss>

