From: "Nike Dattani" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: New challenge! Minimizing the amount of 'unnecessary memory' !
Date: Mon, 14 Mar 2011 02:39:04 +0000 (UTC)
Organization: Oxford University
Lines: 37
Message-ID: <iljv48$pkf$>
References: <ilbujg$rbl$> <ilj63l$kr6$>
Reply-To: "Nike Dattani" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1300070344 26255 (14 Mar 2011 02:39:04 GMT)
NNTP-Posting-Date: Mon, 14 Mar 2011 02:39:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2479384
Xref: comp.soft-sys.matlab:715589

"James Tursa" wrote in message <ilj63l$kr6$>...
> "Nike Dattani" <> wrote in message <ilbujg$rbl$>...
> > 
> > What's even stranger is that even if I define a new temprary variable:
> > temp=((indices(:,end-j)-1)*4+indices(:,end),j+1); 
> > 
> > and now write down the total memory allocated to matlab, and then apply the command:
> > A.*temp;
> > 
> > the amount of memory used by matlab shoots up by more than 1GB during this computation, then goes back down. what it started as.  Why would A.*temp require SO much more memory, which appears to be the amount of memory that A and temp themselves take ??? I thought the whole point of having them in memory is so that we can do basic operations like multiplication very easily without having to dubplicate them !
> FYI, the A.*temp calculation requires that temp first be converted from uint8 to double, hence the big memory increase necessary for the calculation.
> James Tursa

Hi James !
Wow !! Thanks so much for taking the time to write those MEX routines !
That's incredibly kind, and I really appreciate it !

I was actually about to try writing a MEX routine in FORTRAN since array slicing can be done in FORTRAN , and that way I could hopefully avoid the for loops and do something that more closesly resembles: A.*K((indices(:,end-j)-1)*4+indices(:,end),j+1) 

My intuition is that doing array multiplications is faster than doing forloops .. but I'm often wrong about these things.
I made a crucial typo in both of my posts:

should actually read:

A.*temp is exactly what I'm calculating, which is: 

So everything is already double precision.
But now I'm not able to reproduce the behaviour I noticed before .. 
Maybe Matlab isn't using up so much more RAM than necessary after all!