Thread Subject: Memory error on subsequent assignment

Subject: Memory error on subsequent assignment

From: Mark

Date: 8 Jul, 2008 04:01:05

Message: 1 of 2

I know most of the memory error issues (contiguous blocks
etc) but can't quite understand why it is I'm getting an out
of memory error on a particular line. I do the right thing
and pre-allocate the memory block using...

mth_ret = zeros(nsims, mths, ac, 'single');

but get the out of memory error in the subsequent loop that
performs variable assignment...

for j = 1:ac
    mth_ret(:,:,j) = <variable>.<field>.<var>(1:nsims,:);
end

I was wondering whether the error is caused by Matlab
manipulating the data for assignment or for some other reason?

Thanks.

Subject: Memory error on subsequent assignment

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 8 Jul, 2008 04:15:44

Message: 2 of 2

In article <g4uoq1$20v$1@fred.mathworks.com>,
Mark <nospamthank@yahoo.com> wrote:
>I know most of the memory error issues (contiguous blocks
>etc) but can't quite understand why it is I'm getting an out
>of memory error on a particular line. I do the right thing
>and pre-allocate the memory block using...
>
>mth_ret = zeros(nsims, mths, ac, 'single');
>
>but get the out of memory error in the subsequent loop that
>performs variable assignment...
>
>for j = 1:ac
> mth_ret(:,:,j) = <variable>.<field>.<var>(1:nsims,:);
>end

When you take a sub-section of a vector and it isn't immediately
obvious to Matlab that you are copying vectors of the same size
around, then Matlab may have to take a temporary copy of the source data
as part of the assignment process. The taking of that temporary
copy may fill up memory.

I -believe- Matlab is smart enough to get away without temporary
copies in some straight-forward cases, but my -expectation- is that
those cases would be only when entire columns are copied. I speculate
that it is possible that if you were to reverse the first and second
dimensions of the source and destination that Matlab might perhaps
be able to get away without creating a temporary copy.
--
  "I like to build things, I like to do things. I am having
  a lot of fun." -- Walter Chrysler

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
memory error Mark 8 Jul, 2008 00:05:09
assignment Mark 8 Jul, 2008 00:05:09
single Mark 8 Jul, 2008 00:05:09
zeros Mark 8 Jul, 2008 00:05:09
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com