<?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: Internal Matlab memory optimizations	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=internal-matlab-memory-optimizations</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Mon, 17 Apr 2017 18:12:07 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-405041</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Mon, 17 Apr 2017 18:12:07 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2952#comment-405041</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-405027&quot;&gt;Johannes Rebling&lt;/a&gt;.

@Johannes - you might try to employ &lt;a href=&quot;http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;in-place data manipulation&lt;/a&gt;. See chapter 9 of my performance-tuning book for details.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-405027">Johannes Rebling</a>.</p>
<p>@Johannes &#8211; you might try to employ <a href="http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data" target="_blank" rel="nofollow">in-place data manipulation</a>. See chapter 9 of my performance-tuning book for details.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Johannes Rebling		</title>
		<link>https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-405027</link>

		<dc:creator><![CDATA[Johannes Rebling]]></dc:creator>
		<pubDate>Mon, 17 Apr 2017 08:49:37 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2952#comment-405027</guid>

					<description><![CDATA[Dear Yair Altman,

thank you much for your many insights into Matlab performance. I am currently working with very large datasets in Matlab (20 GB and more) which I need to reshape, crop, filter, ... . My code uses dedicated functions for most operations for clarity and reusability. I pass structures containing the data set to those functions and return an updated version of that structure back to the invoking function. As a simple example:
&lt;pre lang=&quot;matlab&quot;&gt;
A.data = rand(50,50);
A = my_function(A);
&lt;/pre&gt;
where my_function would then do something like:
&lt;pre lang=&quot;matlab&quot;&gt;
function A = my_function(A)
A.data = filter(A.data);
end
&lt;/pre&gt;

This does not seem to be memory efficient since a copy of the original data is created and hence I need twice as much memory at some point which becomes a problem if the data array is bigger than half my physical memory. I was wondering if you have an idea on how to solve this? Would it be wise to store my large dataset in a global variable and operate on that? Are there potential drawbacks to this approach?

Best,
Johannes]]></description>
			<content:encoded><![CDATA[<p>Dear Yair Altman,</p>
<p>thank you much for your many insights into Matlab performance. I am currently working with very large datasets in Matlab (20 GB and more) which I need to reshape, crop, filter, &#8230; . My code uses dedicated functions for most operations for clarity and reusability. I pass structures containing the data set to those functions and return an updated version of that structure back to the invoking function. As a simple example:</p>
<pre lang="matlab">
A.data = rand(50,50);
A = my_function(A);
</pre>
<p>where my_function would then do something like:</p>
<pre lang="matlab">
function A = my_function(A)
A.data = filter(A.data);
end
</pre>
<p>This does not seem to be memory efficient since a copy of the original data is created and hence I need twice as much memory at some point which becomes a problem if the data array is bigger than half my physical memory. I was wondering if you have an idea on how to solve this? Would it be wise to store my large dataset in a global variable and operate on that? Are there potential drawbacks to this approach?</p>
<p>Best,<br />
Johannes</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Accessing private object properties &#124; Undocumented Matlab		</title>
		<link>https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-304769</link>

		<dc:creator><![CDATA[Accessing private object properties &#124; Undocumented Matlab]]></dc:creator>
		<pubDate>Wed, 18 Dec 2013 18:14:43 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2952#comment-304769</guid>

					<description><![CDATA[[...] properties. mxSetProperty is a dead-end for similar reasons.The core idea behind the solution is Matlab&#8217;s Copy-on-Write mechanism (COW). This basically means that when our struct is created, the field values actually hold [...]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] properties. mxSetProperty is a dead-end for similar reasons.The core idea behind the solution is Matlab&#8217;s Copy-on-Write mechanism (COW). This basically means that when our struct is created, the field values actually hold [&#8230;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Class object creation performance &#124; Undocumented Matlab		</title>
		<link>https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-303734</link>

		<dc:creator><![CDATA[Class object creation performance &#124; Undocumented Matlab]]></dc:creator>
		<pubDate>Wed, 11 Dec 2013 16:50:54 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2952#comment-303734</guid>

					<description><![CDATA[[...] created and then the modified class needs to be copied back to the original object&#039;s memory (using Matlab&#039;s Copy-on-Write mechanism). Since we cannot normally anticipate all usage patterns of a class when we create it, I suggest to [...]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] created and then the modified class needs to be copied back to the original object&#039;s memory (using Matlab&#039;s Copy-on-Write mechanism). Since we cannot normally anticipate all usage patterns of a class when we create it, I suggest to [&#8230;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-88693</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 02 Jun 2012 18:03:33 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2952#comment-88693</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-88558&quot;&gt;Steve C&lt;/a&gt;.

@Steve - As I noted in my article: In order to benefit from in-place optimizations of function results, we must both use the same variable in the caller workspace (x = function1(x)) and also ensure that the called function is optimizable (e.g., function x = function1(x)) – if any of these two requirements is not met then in-place function-call optimization is not performed. 

The way I understand it, based on &lt;a href=&quot;http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-16225&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Loren&#039;s comment&lt;/a&gt; back in 2007, is that funcB would NOT be optimized, unless the JIT was improved in recent years to take this into account. If this is the case, then perhaps a kind MathWorker could enlighten us with a follow-up comment here. Otherwise we should assume that what I wrote above is still correct.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-88558">Steve C</a>.</p>
<p>@Steve &#8211; As I noted in my article: In order to benefit from in-place optimizations of function results, we must both use the same variable in the caller workspace (x = function1(x)) and also ensure that the called function is optimizable (e.g., function x = function1(x)) – if any of these two requirements is not met then in-place function-call optimization is not performed. </p>
<p>The way I understand it, based on <a href="http://blogs.mathworks.com/loren/2007/03/22/in-place-operations-on-data/#comment-16225" target="_blank" rel="nofollow">Loren&#8217;s comment</a> back in 2007, is that funcB would NOT be optimized, unless the JIT was improved in recent years to take this into account. If this is the case, then perhaps a kind MathWorker could enlighten us with a follow-up comment here. Otherwise we should assume that what I wrote above is still correct.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Steve C		</title>
		<link>https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-88558</link>

		<dc:creator><![CDATA[Steve C]]></dc:creator>
		<pubDate>Fri, 01 Jun 2012 20:29:35 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2952#comment-88558</guid>

					<description><![CDATA[I&#039;m wondering, given the desire to assign results to the same variable to optimize the copy on write, if there is any benifit to coding functions such that they return the exact same variable name passed in. Does the in-place optimization still work correctly in case of funcB() as in funcA()? Does this local variable assignment make any difference with the optimizations if the outer assignment is to the same variable? How deeply does the optimizer follow references? I would think funcB would cloan the data on write before returning it to the calling scope. 

&lt;pre lang=&quot;matlab&quot;&gt;
aMatrix = funcA(aMatrix); % assignment to same var

function [param] = funcA(param)
% param in and param out are the same var
param = param * 10;
end
&lt;/pre&gt;

verses:
&lt;pre lang=&quot;matlab&quot;&gt;
aMatrix = funcB(aMatrix); % assignment to same var

function [param_out] = funcB(param_in)
% param in and param out are Not the same var
param_out = param_in * 10;
end
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m wondering, given the desire to assign results to the same variable to optimize the copy on write, if there is any benifit to coding functions such that they return the exact same variable name passed in. Does the in-place optimization still work correctly in case of funcB() as in funcA()? Does this local variable assignment make any difference with the optimizations if the outer assignment is to the same variable? How deeply does the optimizer follow references? I would think funcB would cloan the data on write before returning it to the calling scope. </p>
<pre lang="matlab">
aMatrix = funcA(aMatrix); % assignment to same var

function [param] = funcA(param)
% param in and param out are the same var
param = param * 10;
end
</pre>
<p>verses:</p>
<pre lang="matlab">
aMatrix = funcB(aMatrix); % assignment to same var

function [param_out] = funcB(param_in)
% param in and param out are Not the same var
param_out = param_in * 10;
end
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Clayton Chu		</title>
		<link>https://undocumentedmatlab.com/articles/internal-matlab-memory-optimizations#comment-88207</link>

		<dc:creator><![CDATA[Clayton Chu]]></dc:creator>
		<pubDate>Wed, 30 May 2012 17:01:25 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2952#comment-88207</guid>

					<description><![CDATA[I wish MATLAB had pointers or references without having to write a handle subclass.]]></description>
			<content:encoded><![CDATA[<p>I wish MATLAB had pointers or references without having to write a handle subclass.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
