<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Memory Management for Functions and Variables</title>
	<atom:link href="http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Thu, 09 Feb 2012 04:19:21 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-32340</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 20 Jun 2011 15:39:31 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-32340</guid>
		<description>umibozuuu-

I mean indexing into tmp for assignment like:

tmp(ind1,ind2) = whatever

--Loren</description>
		<content:encoded><![CDATA[<p>umibozuuu-</p>
<p>I mean indexing into tmp for assignment like:</p>
<p>tmp(ind1,ind2) = whatever</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: umibozuuu</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-32339</link>
		<dc:creator>umibozuuu</dc:creator>
		<pubDate>Mon, 20 Jun 2011 15:37:45 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-32339</guid>
		<description>Hello Loren, 
sorry for being slow here, but
I&#039;m not sure I understand what you mean by &quot;index into the tmp variable&quot;? Is there a way to assign a value to tmp without reallocating?</description>
		<content:encoded><![CDATA[<p>Hello Loren,<br />
sorry for being slow here, but<br />
I&#8217;m not sure I understand what you mean by &#8220;index into the tmp variable&#8221;? Is there a way to assign a value to tmp without reallocating?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-32338</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Mon, 20 Jun 2011 15:04:16 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-32338</guid>
		<description>umibozuuu,

That&#039;s simple.  YOu are asking for the allocation by saying &quot;tmp=&quot;

Memory will always be allocated for tmp under that sort of situation.  You need to index into the tmp variable you preallocated for it to reuse the memory, even though tmp is shared from the parent to the nested function.

--Loren</description>
		<content:encoded><![CDATA[<p>umibozuuu,</p>
<p>That&#8217;s simple.  YOu are asking for the allocation by saying &#8220;tmp=&#8221;</p>
<p>Memory will always be allocated for tmp under that sort of situation.  You need to index into the tmp variable you preallocated for it to reuse the memory, even though tmp is shared from the parent to the nested function.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: umibozuuu</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-32336</link>
		<dc:creator>umibozuuu</dc:creator>
		<pubDate>Mon, 20 Jun 2011 13:52:13 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-32336</guid>
		<description>Hello,
I am having a problem where it seems &quot;assignment forces allocation&quot;- inside a function called by its handle. I&#039;d like to know if it&#039;s possible to avoid the repeated memory allocations that I show below.
There is this function I call by its handle repeatedly, which does a little computation for which it is useful to store a large temp (always the same size of temp every time the function is called). I thought it good to allocate space for the temp once and for all inside the function that produces the function_handle. However when I profile with memory on it seems memory is being allocated at each call 
&lt;pre&gt;
function fh= get_fctr(X);
n=size(X,1);
tmp=zeros(n,1);
fh=@fcn_implem;
function [res1,res2]=function_implem(i)
 tmp=known_function0(X,i);%here!this is where allocation is %happening and I don&#039;t understand why!
 res1=known_function1(tmp,i);
 res2=known_function2(tmp,i);
end
end
%now in a &#039;main&#039; function I am calling this functor several %times.
afunc=get_fctr(anX);
for i=1:largenumber
store_results(:,i)=afunc(i);
end
&lt;/pre&gt;
and for some reason I don&#039;t know why it needs to reallocate the tmp inside the function every time instead of just once when I do the &quot;afunc=get_fctr(anX)&quot; call.
Hope this is clear enough? Thanks!</description>
		<content:encoded><![CDATA[<p>Hello,<br />
I am having a problem where it seems &#8220;assignment forces allocation&#8221;- inside a function called by its handle. I&#8217;d like to know if it&#8217;s possible to avoid the repeated memory allocations that I show below.<br />
There is this function I call by its handle repeatedly, which does a little computation for which it is useful to store a large temp (always the same size of temp every time the function is called). I thought it good to allocate space for the temp once and for all inside the function that produces the function_handle. However when I profile with memory on it seems memory is being allocated at each call </p>
<pre>
function fh= get_fctr(X);
n=size(X,1);
tmp=zeros(n,1);
fh=@fcn_implem;
function [res1,res2]=function_implem(i)
 tmp=known_function0(X,i);%here!this is where allocation is %happening and I don't understand why!
 res1=known_function1(tmp,i);
 res2=known_function2(tmp,i);
end
end
%now in a 'main' function I am calling this functor several %times.
afunc=get_fctr(anX);
for i=1:largenumber
store_results(:,i)=afunc(i);
end
</pre>
<p>and for some reason I don&#8217;t know why it needs to reallocate the tmp inside the function every time instead of just once when I do the &#8220;afunc=get_fctr(anX)&#8221; call.<br />
Hope this is clear enough? Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-31439</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 18 Jun 2010 13:41:05 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-31439</guid>
		<description>Arvind-

Yes, object properties also take advantage of the copy-on-write behavior.   If you are on windows, you can watch the task manager memory plot as you assign to an object&#039;s property and you should see no memory spike.

--Loren</description>
		<content:encoded><![CDATA[<p>Arvind-</p>
<p>Yes, object properties also take advantage of the copy-on-write behavior.   If you are on windows, you can watch the task manager memory plot as you assign to an object&#8217;s property and you should see no memory spike.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arvind Raghavan</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-31438</link>
		<dc:creator>Arvind Raghavan</dc:creator>
		<pubDate>Fri, 18 Jun 2010 13:37:42 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-31438</guid>
		<description>Hi, 

I have a specific question: 
Does Matlab implement copy-on-write even for arrays passed in as arguments when constructing an object? From profiling output I&#039;ve observed, I am lead to suspect that it there may be some kind of copy-on-access behavior for large arrays passed in to the constructor of class. 

Sorry for the cross-post, but I didn&#039;t get any responses when I posted a more detailed version of this question on the newsgroup at:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/284793#755110

(I have a code snippet in that post along with profiling output). 

Thanks for reading,

Arvind</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>I have a specific question:<br />
Does Matlab implement copy-on-write even for arrays passed in as arguments when constructing an object? From profiling output I&#8217;ve observed, I am lead to suspect that it there may be some kind of copy-on-access behavior for large arrays passed in to the constructor of class. </p>
<p>Sorry for the cross-post, but I didn&#8217;t get any responses when I posted a more detailed version of this question on the newsgroup at:</p>
<p><a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/284793#755110" rel="nofollow">http://www.mathworks.com/matlabcentral/newsreader/view_thread/284793#755110</a></p>
<p>(I have a code snippet in that post along with profiling output). </p>
<p>Thanks for reading,</p>
<p>Arvind</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-31437</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Fri, 18 Jun 2010 10:45:15 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-31437</guid>
		<description>Anis-

I recommend you look at &lt;a href=&quot;http://www.mathworks.com/support/tech-notes/1100/1106.html?BB=1&quot; rel=&quot;nofollow&quot;&gt;tech support guide to memory management&lt;/a&gt;.  It has programming tips, ways to set up your computer environment etc.

--Loren</description>
		<content:encoded><![CDATA[<p>Anis-</p>
<p>I recommend you look at <a href="http://www.mathworks.com/support/tech-notes/1100/1106.html?BB=1" rel="nofollow">tech support guide to memory management</a>.  It has programming tips, ways to set up your computer environment etc.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anis</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-31436</link>
		<dc:creator>Anis</dc:creator>
		<pubDate>Fri, 18 Jun 2010 08:39:35 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-31436</guid>
		<description>Hello

I am running some mex file and getting out of memory error.
When i use &quot;memory&quot; command from matlab prompt i can see matlab is using only around 10% of the total physical memory available. Also, when i add up all the arrays that i am declaring inside mex file, it becomes only few percent of total memory available. 

Now my question is - can  we ask matlab to use more memory from the available RAM or is there any other alternate without buying a new computer/etc.  

Thanks
Anis</description>
		<content:encoded><![CDATA[<p>Hello</p>
<p>I am running some mex file and getting out of memory error.<br />
When i use &#8220;memory&#8221; command from matlab prompt i can see matlab is using only around 10% of the total physical memory available. Also, when i add up all the arrays that i am declaring inside mex file, it becomes only few percent of total memory available. </p>
<p>Now my question is &#8211; can  we ask matlab to use more memory from the available RAM or is there any other alternate without buying a new computer/etc.  </p>
<p>Thanks<br />
Anis</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-31067</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Wed, 10 Feb 2010 14:51:58 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-31067</guid>
		<description>Michele-

Not sure what you are asking.  Sounds like you&#039;ve figured out how to get better performance.  

--Loren</description>
		<content:encoded><![CDATA[<p>Michele-</p>
<p>Not sure what you are asking.  Sounds like you&#8217;ve figured out how to get better performance.  </p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michele Williams</title>
		<link>http://blogs.mathworks.com/loren/2006/05/10/memory-management-for-functions-and-variables/#comment-31066</link>
		<dc:creator>Michele Williams</dc:creator>
		<pubDate>Wed, 10 Feb 2010 14:41:19 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=36#comment-31066</guid>
		<description>Hmmmm, my code fragment didn&#039;t show up. This is the print statement: print(filenum,&#039;-dtiff&#039;,filename); where filenum is a string like ‘-f1′ (1 indicates figure 1) and filename is a string like ’segment1′.</description>
		<content:encoded><![CDATA[<p>Hmmmm, my code fragment didn&#8217;t show up. This is the print statement: print(filenum,&#8217;-dtiff&#8217;,filename); where filenum is a string like ‘-f1′ (1 indicates figure 1) and filename is a string like ’segment1′.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

