<?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: Class object creation performance	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/class-object-creation-performance/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/class-object-creation-performance?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=class-object-creation-performance</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 18 Dec 2013 18:16:43 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Accessing private object properties &#124; Undocumented Matlab		</title>
		<link>https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-304770</link>

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

					<description><![CDATA[[...] a copy of the original. Even if our original object is a handle class, the struct would still be a shallow copy and not a real reference to the object data.Mex&#8217;s standard mxGetProperty cannot be used on [...]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] a copy of the original. Even if our original object is a handle class, the struct would still be a shallow copy and not a real reference to the object data.Mex&#8217;s standard mxGetProperty cannot be used on [&#8230;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303942</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 12 Dec 2013 19:24:29 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4496#comment-303942</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303941&quot;&gt;Matt Whitaker&lt;/a&gt;.

@Matt - thanks for the clarification]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303941">Matt Whitaker</a>.</p>
<p>@Matt &#8211; thanks for the clarification</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Matt Whitaker		</title>
		<link>https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303941</link>

		<dc:creator><![CDATA[Matt Whitaker]]></dc:creator>
		<pubDate>Thu, 12 Dec 2013 19:22:16 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4496#comment-303941</guid>

					<description><![CDATA[Hi Yair,
A note on the preallocation. If you have a parameter passed in on your class the automatically expanding classes will be called with a parameter constructor

So if your Widgets class had a varargin input for example then when you try

&lt;pre lang=&quot;matlab&quot;&gt;
array(9)=Widgets(&#039;param&#039;);
&lt;/pre&gt;
 will call the constructor passing &#039;param&#039; in varargin{1} for the first constructor but then passes in an empty varargin for the next
So the moral I think is to have a no-parameter constructor defined if you are going to use this.

At least that&#039;s the way it seems to work on my R2012b
Cheers

Matt]]></description>
			<content:encoded><![CDATA[<p>Hi Yair,<br />
A note on the preallocation. If you have a parameter passed in on your class the automatically expanding classes will be called with a parameter constructor</p>
<p>So if your Widgets class had a varargin input for example then when you try</p>
<pre lang="matlab">
array(9)=Widgets('param');
</pre>
<p> will call the constructor passing &#8216;param&#8217; in varargin{1} for the first constructor but then passes in an empty varargin for the next<br />
So the moral I think is to have a no-parameter constructor defined if you are going to use this.</p>
<p>At least that&#8217;s the way it seems to work on my R2012b<br />
Cheers</p>
<p>Matt</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: MatMan		</title>
		<link>https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303894</link>

		<dc:creator><![CDATA[MatMan]]></dc:creator>
		<pubDate>Thu, 12 Dec 2013 14:24:45 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4496#comment-303894</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303863&quot;&gt;MatMan&lt;/a&gt;.

A small addition:
matlab.mixin.Copyable can also be used for deep copies by overloading the copyElement method as described in the documentation.
Thanks for clearing up that when it was added!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303863">MatMan</a>.</p>
<p>A small addition:<br />
matlab.mixin.Copyable can also be used for deep copies by overloading the copyElement method as described in the documentation.<br />
Thanks for clearing up that when it was added!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303884</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Thu, 12 Dec 2013 12:43:16 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4496#comment-303884</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303863&quot;&gt;MatMan&lt;/a&gt;.

Thanks for mentioning this, &lt;i&gt;&lt;b&gt;matlab.mixin.Copyable&lt;/b&gt;&lt;/i&gt; can indeed be useful for fast shallow copies, in cases that do not require deep copies. And yes, it was indeed added in R2011a. 

Readers interested in object copying might find the following discussion interesting: &lt;a target=&quot;_blank&quot; href=&quot;https://www.mathworks.com/matlabcentral/newsreader/view_thread/257925&quot; rel=&quot;nofollow&quot;&gt;https://www.mathworks.com/matlabcentral/newsreader/view_thread/257925&lt;/a&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303863">MatMan</a>.</p>
<p>Thanks for mentioning this, <i><b>matlab.mixin.Copyable</b></i> can indeed be useful for fast shallow copies, in cases that do not require deep copies. And yes, it was indeed added in R2011a. </p>
<p>Readers interested in object copying might find the following discussion interesting: <a target="_blank" href="https://www.mathworks.com/matlabcentral/newsreader/view_thread/257925" rel="nofollow">https://www.mathworks.com/matlabcentral/newsreader/view_thread/257925</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: MatMan		</title>
		<link>https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303863</link>

		<dc:creator><![CDATA[MatMan]]></dc:creator>
		<pubDate>Thu, 12 Dec 2013 10:27:51 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4496#comment-303863</guid>

					<description><![CDATA[You could have mentioned that since Matlab 2011a (I think) you can copy handle classes without invoking the constructor: http://www.mathworks.com/help/matlab/ref/matlab.mixin.copyableclass.html

Instead of a pool of objects I store only one object and create as many copies as I need when I need them. I haven&#039;t analyzed if a factory approach would be faster though...]]></description>
			<content:encoded><![CDATA[<p>You could have mentioned that since Matlab 2011a (I think) you can copy handle classes without invoking the constructor: <a href="http://www.mathworks.com/help/matlab/ref/matlab.mixin.copyableclass.html" rel="nofollow ugc">http://www.mathworks.com/help/matlab/ref/matlab.mixin.copyableclass.html</a></p>
<p>Instead of a pool of objects I store only one object and create as many copies as I need when I need them. I haven&#8217;t analyzed if a factory approach would be faster though&#8230;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303752</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 11 Dec 2013 19:09:08 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4496#comment-303752</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303748&quot;&gt;Andrew&lt;/a&gt;.

@Andrew - I could indeed make &lt;i&gt;getInstance()&lt;/i&gt; Static+private (no need to make it hidden), but then I&#039;d need to call it via the &lt;code&gt;Widgets.&lt;/code&gt; prefix in &lt;i&gt;pull()/recycle()&lt;/i&gt;:
&lt;pre lang=&#039;matlab&#039;&gt;obj = Widgets.getInstance();&lt;/pre&gt;

There&#039;s also the small matter of performance - I believe that calling a sub-function as in my implementation is slightly faster than a class method invocation.

Not major reasons, I admit. There&#039;s a lot of personal taste that goes into such implementations, and there are of course other good implementations. I&#039;ve lost count of the number of singleton implementations I&#039;ve seen over the years. It&#039;s one of those classes that every newbie gets to program as an exercise, and doesn&#039;t know that he got it wrong until he&#039;s shown his/her errors in a technical job interview. Hopefully, my implementation doesn&#039;t fall into this latter category...

As for not making Widgets Sealed, I see no reason to prevent sub-classes from reimplementing the pool differently. For example, instead of retrieving the last-recycled object, retrieving the oldest one in the pool.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303748">Andrew</a>.</p>
<p>@Andrew &#8211; I could indeed make <i>getInstance()</i> Static+private (no need to make it hidden), but then I&#8217;d need to call it via the <code>Widgets.</code> prefix in <i>pull()/recycle()</i>:</p>
<pre lang='matlab'>obj = Widgets.getInstance();</pre>
<p>There&#8217;s also the small matter of performance &#8211; I believe that calling a sub-function as in my implementation is slightly faster than a class method invocation.</p>
<p>Not major reasons, I admit. There&#8217;s a lot of personal taste that goes into such implementations, and there are of course other good implementations. I&#8217;ve lost count of the number of singleton implementations I&#8217;ve seen over the years. It&#8217;s one of those classes that every newbie gets to program as an exercise, and doesn&#8217;t know that he got it wrong until he&#8217;s shown his/her errors in a technical job interview. Hopefully, my implementation doesn&#8217;t fall into this latter category&#8230;</p>
<p>As for not making Widgets Sealed, I see no reason to prevent sub-classes from reimplementing the pool differently. For example, instead of retrieving the last-recycled object, retrieving the oldest one in the pool.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Andrew		</title>
		<link>https://undocumentedmatlab.com/articles/class-object-creation-performance#comment-303748</link>

		<dc:creator><![CDATA[Andrew]]></dc:creator>
		<pubDate>Wed, 11 Dec 2013 18:39:18 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=4496#comment-303748</guid>

					<description><![CDATA[Interesting use of The MathWorks calls &quot;class-related&quot; functions. Is there a reason that you didn&#039;t make getInstance() an (Access=private,Static,Hidden) method instead? Also, is there a reason for not making Widgets a (Sealed) class to prevent subclassing?]]></description>
			<content:encoded><![CDATA[<p>Interesting use of The MathWorks calls &#8220;class-related&#8221; functions. Is there a reason that you didn&#8217;t make getInstance() an (Access=private,Static,Hidden) method instead? Also, is there a reason for not making Widgets a (Sealed) class to prevent subclassing?</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
