<?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: All hail the &#8220;const&#8221; parameters!</title>
	<atom:link href="http://delphitools.info/2010/07/28/all-hail-the-const-parameters/feed/" rel="self" type="application/rss+xml" />
	<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/</link>
	<description>SamplingProfiler, DWS and other Delphi tools</description>
	<lastBuildDate>Wed, 15 Feb 2012 22:38:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Jon Lennart Aasenden</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1232</link>
		<dc:creator>Jon Lennart Aasenden</dc:creator>
		<pubDate>Fri, 20 Aug 2010 17:12:56 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1232</guid>
		<description>The &quot;Var&quot; clause is also pointer based right?</description>
		<content:encoded><![CDATA[<p>The &#8220;Var&#8221; clause is also pointer based right?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Georges Varouchas</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1212</link>
		<dc:creator>Georges Varouchas</dc:creator>
		<pubDate>Fri, 30 Jul 2010 07:35:42 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1212</guid>
		<description>Another case when &quot;CONST&quot; makes a big difference : open arrays.

If you call :
    function DoSmth( aArray : array of Integer );
DoSmth(myArray) will actually make a *complete copy of myArray&#039;s content on the stack*.

On the other hand :
    function DoSmth( const aArray : array of Integer );
DoSmth(myArray) will only take a pointer to myArray.

And obviously, what is mentioned in this post also apply to &quot;var&quot; arguments - together with the advantages and dangers of having parameters passed as reference.</description>
		<content:encoded><![CDATA[<p>Another case when &#8220;CONST&#8221; makes a big difference : open arrays.</p>
<p>If you call :<br />
    function DoSmth( aArray : array of Integer );<br />
DoSmth(myArray) will actually make a *complete copy of myArray&#8217;s content on the stack*.</p>
<p>On the other hand :<br />
    function DoSmth( const aArray : array of Integer );<br />
DoSmth(myArray) will only take a pointer to myArray.</p>
<p>And obviously, what is mentioned in this post also apply to &#8220;var&#8221; arguments &#8211; together with the advantages and dangers of having parameters passed as reference.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas Hausladen</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1211</link>
		<dc:creator>Andreas Hausladen</dc:creator>
		<pubDate>Thu, 29 Jul 2010 10:26:03 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1211</guid>
		<description>@Tommi Prami: The option can be set in the project options. But you can enable and disable it in every unit if you want.</description>
		<content:encoded><![CDATA[<p>@Tommi Prami: The option can be set in the project options. But you can enable and disable it in every unit if you want.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tommi Prami</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1210</link>
		<dc:creator>Tommi Prami</dc:creator>
		<pubDate>Thu, 29 Jul 2010 06:22:20 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1210</guid>
		<description>&lt;a href=&quot;#comment-1209&quot; rel=&quot;nofollow&quot;&gt;@Andreas Hausladen&lt;/a&gt;

That is so good to know, I am just learlning the Delphi-Unicode world. Not sure about the timeframe when I really need to make the jump, but I&#039;ve been looking it past few days, and porting some old code for D2009+ and I surely did not know about that option. Is there option in projeect level, or do I need to use .Inc file for that?</description>
		<content:encoded><![CDATA[<p><a href="#comment-1209" rel="nofollow">@Andreas Hausladen</a></p>
<p>That is so good to know, I am just learlning the Delphi-Unicode world. Not sure about the timeframe when I really need to make the jump, but I&#8217;ve been looking it past few days, and porting some old code for D2009+ and I surely did not know about that option. Is there option in projeect level, or do I need to use .Inc file for that?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas Hausladen</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1209</link>
		<dc:creator>Andreas Hausladen</dc:creator>
		<pubDate>Thu, 29 Jul 2010 05:29:58 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1209</guid>
		<description>Unfortunately if you have the &quot;{$STRINGCHECKS ON}&quot; (what is the default value) in Delphi 2009/2010. The &quot;const&quot; becomes irrelevant, because the compiler will always emit the implicit try/finally and the code that manages the RefCount. That&#039;s why I disable this stupid compiler option in all of my projects. StringChecks are for not correctly migrated C++Builder projects. Delphi projects experience a bad hit in string-performance.</description>
		<content:encoded><![CDATA[<p>Unfortunately if you have the &#8220;{$STRINGCHECKS ON}&#8221; (what is the default value) in Delphi 2009/2010. The &#8220;const&#8221; becomes irrelevant, because the compiler will always emit the implicit try/finally and the code that manages the RefCount. That&#8217;s why I disable this stupid compiler option in all of my projects. StringChecks are for not correctly migrated C++Builder projects. Delphi projects experience a bad hit in string-performance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gad D Lord</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1208</link>
		<dc:creator>Gad D Lord</dc:creator>
		<pubDate>Wed, 28 Jul 2010 20:23:53 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1208</guid>
		<description>I have been &quot;const&quot;-ing for about 10 years. Now I have a good &quot;Look - I told you&quot; article to refer to. Thank you for your observations.</description>
		<content:encoded><![CDATA[<p>I have been &#8220;const&#8221;-ing for about 10 years. Now I have a good &#8220;Look &#8211; I told you&#8221; article to refer to. Thank you for your observations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: A. Bouchez</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1207</link>
		<dc:creator>A. Bouchez</dc:creator>
		<pubDate>Wed, 28 Jul 2010 18:55:23 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1207</guid>
		<description>const string parameters is always a good idea.

But perhaps it worth saying a word about integer and floating-point parameters: there is no difference in code generation for integer and floating-point values. There is only a difference in usage inside the function/procedure/method: if defined as const, you can&#039;t assign another value to them.</description>
		<content:encoded><![CDATA[<p>const string parameters is always a good idea.</p>
<p>But perhaps it worth saying a word about integer and floating-point parameters: there is no difference in code generation for integer and floating-point values. There is only a difference in usage inside the function/procedure/method: if defined as const, you can&#8217;t assign another value to them.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: François</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1206</link>
		<dc:creator>François</dc:creator>
		<pubDate>Wed, 28 Jul 2010 17:26:55 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1206</guid>
		<description>I so fully agree that I wish the default for passing parameters had been const instead of passing them by value. 
Then if you&#039;d really need to modify the parameter inside the function you could opt out and specifically choose by ref or by value...</description>
		<content:encoded><![CDATA[<p>I so fully agree that I wish the default for passing parameters had been const instead of passing them by value.<br />
Then if you&#8217;d really need to modify the parameter inside the function you could opt out and specifically choose by ref or by value&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1205</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Wed, 28 Jul 2010 15:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1205</guid>
		<description>&lt;a href=&quot;#comment-1200&quot; rel=&quot;nofollow&quot;&gt;@Jeroen Pluimers&lt;/a&gt; 
Fixed, thumbnailing kicked in.
edit... hmm no good, I&#039;ll reenable the thumbnailing, you can click on the mage to get a zoomed unblurred view</description>
		<content:encoded><![CDATA[<p><a href="#comment-1200" rel="nofollow">@Jeroen Pluimers</a><br />
Fixed, thumbnailing kicked in.<br />
edit&#8230; hmm no good, I&#8217;ll reenable the thumbnailing, you can click on the mage to get a zoomed unblurred view</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://delphitools.info/2010/07/28/all-hail-the-const-parameters/comment-page-1/#comment-1204</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Wed, 28 Jul 2010 15:17:58 +0000</pubDate>
		<guid isPermaLink="false">http://delphitools.info/?p=483#comment-1204</guid>
		<description>&lt;a href=&quot;#comment-1199&quot; rel=&quot;nofollow&quot;&gt;@Rob McDonell&lt;/a&gt;
In practice it&#039;ll depend on how you modify the string, and how many times you&#039;ll access the original string during or after its modification.
Thing is, the copy on write mechanism ensures that in the worst case the const version will only be marginally slower, while best case can be faster.
If your function is a very high frequency critical one, won&#039;t evolve much, and you&#039;ve already optimized all that can be, then you could worry about trying to test if removing the &#039;const&#039; brings a plus, though usually there may be better strategies (usually revolving around how and why you modify the passed string).

In all other cases, my advice would be to stick to the safety of &#039;const&#039;. There are benefits in terms of debugging, resilience of performance to implementation changes, and maintainability, as it&#039;s simpler to check that all strings are passed as &#039;const&#039; in a library rather than check case by case if it&#039;s worth it not using &#039;const&#039; in some cases ;)</description>
		<content:encoded><![CDATA[<p><a href="#comment-1199" rel="nofollow">@Rob McDonell</a><br />
In practice it&#8217;ll depend on how you modify the string, and how many times you&#8217;ll access the original string during or after its modification.<br />
Thing is, the copy on write mechanism ensures that in the worst case the const version will only be marginally slower, while best case can be faster.<br />
If your function is a very high frequency critical one, won&#8217;t evolve much, and you&#8217;ve already optimized all that can be, then you could worry about trying to test if removing the &#8216;const&#8217; brings a plus, though usually there may be better strategies (usually revolving around how and why you modify the passed string).</p>
<p>In all other cases, my advice would be to stick to the safety of &#8216;const&#8217;. There are benefits in terms of debugging, resilience of performance to implementation changes, and maintainability, as it&#8217;s simpler to check that all strings are passed as &#8216;const&#8217; in a library rather than check case by case if it&#8217;s worth it not using &#8216;const&#8217; in some cases <img src='http://delphitools.info/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
<!-- This Quick Cache file was built for (  www.delphitools.info/2010/07/28/all-hail-the-const-parameters/feed/ ) in 1.23476 seconds, on Feb 23rd, 2012 at 2:32 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Feb 24th, 2012 at 2:32 am UTC -->
