<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172179</link>
    <title>MATLAB Central Newsreader - Memory error on subsequent assignment</title>
    <description>Feed for thread: Memory error on subsequent assignment</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>Tue, 08 Jul 2008 04:01:05 -0400</pubDate>
      <title>Memory error on subsequent assignment</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172179#441719</link>
      <author>Mark </author>
      <description>I know most of the memory error issues (contiguous blocks&lt;br&gt;
etc) but can't quite understand why it is I'm getting an out&lt;br&gt;
of memory error on a particular line. I do the right thing&lt;br&gt;
and pre-allocate the memory block using...&lt;br&gt;
&lt;br&gt;
mth_ret = zeros(nsims, mths, ac, 'single');&lt;br&gt;
&lt;br&gt;
but get the out of memory error in the subsequent loop that&lt;br&gt;
performs variable assignment...&lt;br&gt;
&lt;br&gt;
for j = 1:ac&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mth_ret(:,:,j) = &amp;lt;variable&amp;gt;.&amp;lt;field&amp;gt;.&amp;lt;var&amp;gt;(1:nsims,:);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
I was wondering whether the error is caused by Matlab&lt;br&gt;
manipulating the data for assignment or for some other reason?&lt;br&gt;
&lt;br&gt;
Thanks.</description>
    </item>
    <item>
      <pubDate>Tue, 08 Jul 2008 04:15:44 -0400</pubDate>
      <title>Re: Memory error on subsequent assignment</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/172179#441723</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;g4uoq1$20v$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
Mark  &amp;lt;nospamthank@yahoo.com&amp;gt; wrote:&lt;br&gt;
&amp;gt;I know most of the memory error issues (contiguous blocks&lt;br&gt;
&amp;gt;etc) but can't quite understand why it is I'm getting an out&lt;br&gt;
&amp;gt;of memory error on a particular line. I do the right thing&lt;br&gt;
&amp;gt;and pre-allocate the memory block using...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;mth_ret = zeros(nsims, mths, ac, 'single');&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;but get the out of memory error in the subsequent loop that&lt;br&gt;
&amp;gt;performs variable assignment...&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt;for j = 1:ac&lt;br&gt;
&amp;gt;    mth_ret(:,:,j) = &amp;lt;variable&amp;gt;.&amp;lt;field&amp;gt;.&amp;lt;var&amp;gt;(1:nsims,:);&lt;br&gt;
&amp;gt;end&lt;br&gt;
&lt;br&gt;
When you take a sub-section of a vector and it isn't immediately&lt;br&gt;
obvious to Matlab that you are copying vectors of the same size&lt;br&gt;
around, then Matlab may have to take a temporary copy of the source data&lt;br&gt;
as part of the assignment process. The taking of that temporary&lt;br&gt;
copy may fill up memory.&lt;br&gt;
&lt;br&gt;
I -believe- Matlab is smart enough to get away without temporary&lt;br&gt;
copies in some straight-forward cases, but my -expectation- is that&lt;br&gt;
those cases would be only when entire columns are copied. I speculate&lt;br&gt;
that it is possible that if you were to reverse the first and second&lt;br&gt;
dimensions of the source and destination that Matlab might perhaps&lt;br&gt;
be able to get away without creating a temporary copy.&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;&quot;I like to build things, I like to do things. I am having&lt;br&gt;
&amp;nbsp;&amp;nbsp;a lot of fun.&quot;                              -- Walter Chrysler</description>
    </item>
  </channel>
</rss>

