<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Silviu-Marius Ardelean&#039;s Blog</title>
	<atom:link href="http://silviuardelean.ro/feed/" rel="self" type="application/rss+xml" />
	<link>http://silviuardelean.ro</link>
	<description>a software developer web log</description>
	<lastBuildDate>Tue, 14 Feb 2012 09:57:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Happy Birthday, Romania!</title>
		<link>http://silviuardelean.ro/2011/12/01/happy-birthday-romania/</link>
		<comments>http://silviuardelean.ro/2011/12/01/happy-birthday-romania/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 17:41:04 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[Romania]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=1036</guid>
		<description><![CDATA[Today it's the Nation Day of my country!

<em><strong>La Mulţi Ani, România!
Happy Birthday, Romania!
Joyeux Anniversaire, Roumanie!
Alles Gute zum Geburtstag, Rumänien!</strong></em>

<a href="http://silviuardelean.ro/2011/12/01/happy-birthday-romania/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/12/Romanian_Performers-300x210.jpg" alt="" title="Romanian Performers" width="400" height="310" class="aligncenter size-medium wp-image-1099" /></a>]]></description>
			<content:encoded><![CDATA[<p>Today it&#8217;s the Nation Day of my country!</p>
<p><em><strong>La Mulţi Ani, România!<br />
Happy Birthday, Romania!<br />
Joyeux Anniversaire, Roumanie!<br />
Alles Gute zum Geburtstag, Rumänien!</strong></em></p>
<p><a href="http://silviuardelean.ro/romania/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/12/ziua-nationala-a-Romaniei.jpg" alt="" title="ziua nationala a Romaniei" width="450" height="302" class="aligncenter size-full wp-image-1039" /></a></p>
<p>Because my country has some image issues I dedicated a special page about the real <a href="http://silviuardelean.ro/romania/" title="Romania" target="_blank">Romania</a> here! </p>
<p>In case you don&#8217;t know:<br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/12/henri-coanda-engleza-1024x724.png" rel="lightbox[1036]" title="henri-coanda-engleza"><img src="http://silviuardelean.ro/wp-content/uploads/2011/12/henri-coanda-engleza-300x212.png" alt="" title="henri-coanda-engleza" width="440" height="342" class="aligncenter size-medium wp-image-1100" /></a></p>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2011/12/stefan-odobleja-engleza-1024x724.png" rel="lightbox[1036]" title="stefan-odobleja-engleza"><img src="http://silviuardelean.ro/wp-content/uploads/2011/12/stefan-odobleja-engleza-300x212.png" alt="" title="stefan-odobleja-engleza" width="440" height="342" class="aligncenter size-medium wp-image-1055" /></a><br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/12/nadia-comaneci-engleza-1024x724.png" rel="lightbox[1036]" title="nadia-comaneci-engleza"><img src="http://silviuardelean.ro/wp-content/uploads/2011/12/nadia-comaneci-engleza-300x212.png" alt="" title="nadia-comaneci-engleza" width="440" height="342" class="aligncenter size-medium wp-image-1058" /></a><br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/12/nicolae-paulescu-engleza-1024x724.png" rel="lightbox[1036]" title="nicolae-paulescu-engleza"><img src="http://silviuardelean.ro/wp-content/uploads/2011/12/nicolae-paulescu-engleza-300x212.png" alt="" title="nicolae-paulescu-engleza" width="440" height="342" class="aligncenter size-medium wp-image-1057" /></a><br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/12/ilie-nastase-engleza-1024x724.png" rel="lightbox[1036]" title="ilie-nastase-engleza"><img src="http://silviuardelean.ro/wp-content/uploads/2011/12/ilie-nastase-engleza-300x212.png" alt="" title="ilie-nastase-engleza" width="440" height="342" class="aligncenter size-medium wp-image-1056" /></a></p>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2011/12/Romanian_Performers.jpg" rel="lightbox[1036]" title="Romanian Performers"><img src="http://silviuardelean.ro/wp-content/uploads/2011/12/Romanian_Performers-300x210.jpg" alt="" title="Romanian Performers" width="440" height="310" class="aligncenter size-medium wp-image-1099" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2011/12/01/happy-birthday-romania/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun IT &#8211; 2011 Collection</title>
		<link>http://silviuardelean.ro/2011/11/14/fun-it-2011-collection/</link>
		<comments>http://silviuardelean.ro/2011/11/14/fun-it-2011-collection/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 20:36:30 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[IT funny stuff]]></category>
		<category><![CDATA[funny it]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=965</guid>
		<description><![CDATA[Here it is a collection of funny topics that I met this year in my daily activities. In case I will get new info, the topic will be updated! 

<a href="http://silviuardelean.ro/2011/11/14/fun-it-2011-collection/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/11/virusi-la-felix.png" alt="" title="Chatting with a Yahoo Messenger virus" width="541" height="562" class="aligncenter size-full wp-image-966" /></a>

Nobody is perfect and especially the software! :) But it's nice to immortalize funny things.]]></description>
			<content:encoded><![CDATA[<p>Here it is a collection of funny topics that I met this year in my daily activities. In case I will get new info, the topic will be updated!<br />
Nobody is perfect and especially the software! <img src='http://silviuardelean.ro/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  But it&#8217;s nice to immortalize funny things.</p>
<p><strong>Chatting with a virus</strong><br />
Few weeks ago I was chatting with a virus. A friend of mine just got a Yahoo Messenger <a href="http://www.rootishare.com/13942/yahoo-messenger-virus-trojan-yimbot-k.html" target="_blank">virus</a> and unsealed it to me. <img src='http://silviuardelean.ro/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2011/11/virusi-la-felix.png" rel="lightbox[965]" title="Chatting with a Yahoo Messenger virus"><img src="http://silviuardelean.ro/wp-content/uploads/2011/11/virusi-la-felix.png" alt="" title="Chatting with a Yahoo Messenger virus" width="541" height="562" class="aligncenter size-full wp-image-966" /></a></p>
<p>After that I emailed to my friend and his computer is safe now. </p>
<p><strong>Mission Impossible in Eclipse</strong></p>
<p>This year I was involved in a Java project using Eclipse IDE. Once day I tried to export few files in a .jar and I got impossible situation to close the export dialog: all the buttons where disabled and when I tried to close the window using <strong>Alt+F4</strong> or <strong>X</strong> button I got next message error.</p>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2011/11/eclipse-export-wizard-in-the-air.png" rel="lightbox[965]" title="Mission Impossible in Eclipse"><img src="http://silviuardelean.ro/wp-content/uploads/2011/11/eclipse-export-wizard-in-the-air.png" alt="" title="Mission Impossible in Eclipse" width="635" height="597" class="aligncenter size-full wp-image-975" /></a><br />
The only solution to escape this message box was to kill the Eclipse process. Fortunately, the issue didn&#8217;t reproduce second time.</p>
<p><strong>Idle 41 years</strong></p>
<p>This summer, my Pidgin chat application shown over 41 years of <strong>Idle</strong> status for one of my high school colleagues. He is 30 years old. The issue was fixed when he turned back to his computer.</p>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2011/11/ymsg-41-years.png" rel="lightbox[965]" title="Idle 41 years"><img src="http://silviuardelean.ro/wp-content/uploads/2011/11/ymsg-41-years.png" alt="" title="Idle 41 years" width="282" height="707" class="aligncenter size-full wp-image-979" /></a></p>
<p><strong>An original way to say &#8220;Happy Birthday, Austria&#8221;</strong></p>
<p>26 October is the National Day of <a href="http://de.wikipedia.org/wiki/%C3%96sterreich" target="_blank">Austria</a>. On this occasion, Google Translate wished <strong>Happy Birthday Austria</strong> in an original way.</p>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2011/11/goagal-transateaza1.png" rel="lightbox[965]" title="Google Translate - USA vs Austria"><img src="http://silviuardelean.ro/wp-content/uploads/2011/11/goagal-transateaza1.png" alt="" title="Google Translate - USA vs Austria" width="500" height="196" class="aligncenter size-medium wp-image-1108" /></a></p>
<p>The translation from Deutsche to Romanian of &#8220;Happy Birthday Austria! See you soon!&#8221; is &#8220;<em>Happy Birthday USA! See you soon!</em>&#8220;. Today, 14.11.2011, the issue still exists. So Enjoy! </p>
<p><strong>Pidgin relapses</strong><br />
Today, 15.12.2011, according to Pidgin 2.7.11 one of my office colleagues was out of office over 41 years.<br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/11/idle-41-years-pidgin.png" rel="lightbox[965]" title="41 years in less then 10 minutes with Pidgin 2.7.11"><img src="http://silviuardelean.ro/wp-content/uploads/2011/11/idle-41-years-pidgin.png" alt="" title="41 years in less then 10 minutes with Pidgin 2.7.11" width="286" height="296" class="aligncenter size-full wp-image-1118" /></a></p>
<p><strong>Out of Memory &#8211; Yahoo mail</strong><br />
Few days ago I was visiting few private insurances companies. One of the most friendly company&#8217;s employee staid close to me with her laptop. In the moment she tried to send me a PDF file by email using a Yahoo email I was delighted with an amazing message error:<br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/11/out_of_memory_yahoo_email.png" rel="lightbox[965]" title="Out of Memory at line: 1"><img src="http://silviuardelean.ro/wp-content/uploads/2011/11/out_of_memory_yahoo_email-300x169.png" alt="" title="Out of Memory at line: 1" width="300" height="169" class="aligncenter size-medium wp-image-1120" /></a><br />
The using browser was IE 8 in Windows 7. It&#8217;s amazing how she got out of memory at line 1. I don&#8217;t thing Yahoo writes all the code in one line (even if the don&#8217;t use CR + LN). <img src='http://silviuardelean.ro/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2011/11/14/fun-it-2011-collection/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Pictures Unifier 1.1 application is up!</title>
		<link>http://silviuardelean.ro/2011/09/27/simple-pictures-unifier-1-1-application-is-up/</link>
		<comments>http://silviuardelean.ro/2011/09/27/simple-pictures-unifier-1-1-application-is-up/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 10:32:49 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[freeware]]></category>
		<category><![CDATA[photos organizator]]></category>
		<category><![CDATA[pictures organizator]]></category>
		<category><![CDATA[Simple Pictures Unifier]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=878</guid>
		<description><![CDATA[At the beginning of this year I launched an <a href="http://silviuardelean.ro/applications/simple-pictures-unifier/" title="Simple Pictures Unifier">application</a> that helps you to organize the pictures of your important moments. The application helps you specially if you have photos from different sources (different cameras of friends) and you want to have a fluent images story.

From the moment I have launched the first release until now I made up to 12GB pictures (3200+ pictures of 10 MB) and honestly I never found time in order to organize the pictures. Always I rescheduled the application improvements and finally I found time to implement export by date time folders and so on.

<strong>Simple Pictures Unifier 1.1</strong> allows merging and exporting pictures in one folder or in date time folders. Simple Pictures Unifier 1.1 comes with a better user friendly experience and few internal improvements. 
<a href="http://silviuardelean.ro/2011/09/27/simple-pictures-unifier-1-1-application-is-up/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/09/export_wizard_page2_with_main_wnd.png" alt="" title="Simple Pictures Unifier 1.1 - short description" width="701" height="591" class="aligncenter size-full wp-image-886" /></a>]]></description>
			<content:encoded><![CDATA[<p>At the beginning of this year I have launched an <a href="http://silviuardelean.ro/applications/simple-pictures-unifier/" title="Simple Pictures Unifier">application</a> that helps you to organize the pictures of your important moments. The application helps you specially if you have photos from different sources (different cameras of friends) and you want to have a fluent images story.</p>
<p>From the moment I have launched the first release until now I made up to 12GB pictures (3200+ pictures of 10 MB) and honestly I never found time in order to organize the pictures. Always I said that I will complete my application and finally I found time to implement export by date time folders and so on.</p>
<p><a href="http://silviuardelean.ro/applications/simple-pictures-unifier/" title="Simple Pictures Unifier">Simple Pictures Unifier 1.1</a> allows merging and exporting pictures in one folder or in date time folders. The application comes with a better user friendly experience and few internal improvements.<br />
The <strong>Start Export</strong> button launched a new wizard dialog that allows the selection of the preferred export method.</p>
<p><a href="http://silviuardelean.ro/applications/simple-pictures-unifier/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/09/export_wizard_page1_with_main_wnd.png" alt="Export Wizard dialog" title="Export Wizard dialog" width="721" height="611" class="aligncenter size-full wp-image-882" /></a></p>
<p>If the user chooses the default export to date time folders the Export wizard window shows a list with detected time folders.</p>
<p><a href="http://silviuardelean.ro/applications/simple-pictures-unifier/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/09/export_wizard_page2_with_main_wnd.png" alt="" title="Export Wizard - date time folders" width="721" height="611" class="aligncenter size-full wp-image-886" /></a></p>
<p>Selecting <strong>Finish</strong> button the pictures merging is realized and the files are copied to the destination folders. If the user wants to abort the export process it can just press Stop button or close the application with now damages. </p>
<p>Feel free to add comments, suggestions or bugs reports. Any constructive feedback is sincerely appreciated. </p>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2011/09/27/simple-pictures-unifier-1-1-application-is-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adventures with _chkstk</title>
		<link>http://silviuardelean.ro/2011/07/14/adventures-with-chkstk/</link>
		<comments>http://silviuardelean.ro/2011/07/14/adventures-with-chkstk/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 16:06:18 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Other stuff]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[stack overflow]]></category>
		<category><![CDATA[_chkstk crash]]></category>
		<category><![CDATA[_chkstk fail]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=736</guid>
		<description><![CDATA[<em>Called by the compiler when you have more than one page of local variables in your function.
<strong>_chkstk</strong> Routine is a helper routine for the C compiler. For x86 compilers, _chkstk Routine is called when the local variables exceed 4K bytes; for x64 compilers it is 8K.</em>
That’s all that you get from <a target="blank" href="http://msdn.microsoft.com/en-us/library/ms648426(VS.85).aspx">_chkstk()’s msdn</a> web page. Nothing more…

<a href="http://silviuardelean.ro/2011/07/14/adventures-with-chkstk/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/07/callstack_chkstk.png" target="blank" alt="" title="callstack_chkstk" width="566" height="144" class="aligncenter size-full wp-image-742" /></a>]]></description>
			<content:encoded><![CDATA[<p><em>Called by the compiler when you have more than one page of local variables in your function.<br />
<strong>_chkstk</strong> Routine is a helper routine for the C compiler. For x86 compilers, _chkstk Routine is called when the local variables exceed 4K bytes; for x64 compilers it is 8K.</em><br />
That’s all that you get from <a target="blank" href="http://msdn.microsoft.com/en-us/library/ms648426(VS.85).aspx">_chkstk()’s msdn</a> web page. Nothing more…</p>
<p><strong>Overview</strong><br />
A process starts with a fixed stack space. The top of a stack is pointed to by the ESP register (Extended Stack Pointer) and this is a decrementing pointer. Every function calls results in a stack created for the function inside this Process Stack. Every thread function has its own stack. The stack is a downward growing array. When a function starts, the default stack reservation size is 1 MB.<br />
This is contrasting with the heap&#8217;s size whether theoretically increases to a limit of 4 GB on 32bits OS. See more information <a target="blank" href="http://msdn.microsoft.com/en-us/library/bb613473(VS.85).aspx">here</a>.</p>
<p>Every thread under Windows gets its own block of contiguous memory, and while function calls are made, the stack pointer is increasing and decreasing. In contrast, a different thread within the same process might get a different block of contiguous memory &#8211; its own stack.  When a context switch occurs, the current thread&#8217;s ESP (along with the IP and other registers) are saved in the thread&#8217;s context structure, and restored when the thread is activated the next time.<br />
To specify a different default stack reservation size for all threads and fibers, use the STACKSIZE statement in the module definition (.def) file. <a target="blank" href="http://msdn.microsoft.com/en-us/library/ms686774(VS.85).aspx">To change the initially committed stack space</a>, use the dwStackSize parameter of the CreateThread, CreateRemoteThread, or CreateFiber function.<br />
<strong>Most stack problems occur in overflows of existing stacks, as their sizes are fixed and they cannot be expanded.</strong></p>
<p>_chkstk() increases the stack when needed by committing some of the pages previously reserved for the stack. If there is no more physical memory available for committed pages, _chkstk fails. When you enter a function (VC++ with the stack checking enabled), it will call the _chkstk located in CHKSTK.ASM.  This function does a stack page probing and causes the necessary pages of memory to be allocated using the guard page scheme, if possible. In this function, it is stated that when it encounters _XCPT_GUARD_PAGE_VIOLATION, the OS will attempt to allocate another guarded page and if it encounters _XCPT_UNABLE_TO_GROW_STACK then it&#8217;s a stack overflow error. When _XCPT_UNABLE_TO_GROW_STACK is encountered, the stack is not yet set up properly, that is why, that it will not call the catch because calling it will use invalid stack variables which will again cause another exception.</p>
<p><strong>Case &#8211; Too many or too big variables on stack</strong><br />
As I said on top, the function stack size is 1 MB. If you miss that and you’re trying to define and use internally an array like this:</p>
<pre>int arr[4000][200];</pre>
<p>When you’ll compile with VC++ compiler in debug mode you will have a big surprise: the application is crashing on _chkstk() in the moment the _chkstk() tries to create new memory page on stack and fails.<a href="http://silviuardelean.ro/wp-content/uploads/2011/07/callstack_chkstk.png" target="blank" rel="lightbox[736]" title="callstack_chkstk"><img src="http://silviuardelean.ro/wp-content/uploads/2011/07/callstack_chkstk.png" target="blank" alt="" title="callstack_chkstk" width="566" height="144" class="aligncenter size-full wp-image-742" /></a><br />
The output window shows next message:</p>
<pre>
First-chance exception at 0x004116e7 in testApp.exe: 0xC00000FD: Stack overflow.
Unhandled exception at 0x004116e7 in testApp.exe: 0xC00000FD: Stack overflow.
</pre>
<p>This happens because the 1MB limit is overloaded even on a win32 OS: 4000*200*4 = 3.2MB (approx.).<br />
Same story if you define many local variables and their stack usage overloads the 1MB limit.<br />
If you really need this big array then the solution to avoid this crash is using heap.</p>
<pre>
int **arr = new int*[4000];
for(int i=0; i&lt;4000; ++i) {
	arr[i] = new int[200];
}

// and finaly don&#039;t forget to delete
for(int i=0;i&lt;4000; ++i) {
	delete[] arr[i];
}
delete[] arr;
</pre>
<p><strong>Case &#8211; Recursive functions</strong><br />
If you have an infinite recursion then you will gate same stack overflow error and the application crashes in _chkstk.asm. Recursive function is not the subject of this article so I don’t go in deep… <a target="blank" href="http://www.sparknotes.com/cs/recursion/whatisrecursion/section1.html">Here</a> it is a good example of what happens with recursive functions.<br />
The solution is to avoid using recursive functions as much as possible and try to implement an iterative function. </p>
<p><strong>Case &#8211; A stack corruption</strong><br />
I have started looking over _chkstk() function in the moment when I got few bugs with crashes with some similarly details. I had to analyze some .dump files and solve few bugs that contained a call stack with <strong>_chkstk()</strong> on top.<br />
Most of the .dump files call stack contained a second similarly thing: the call of a thread function (so called <strong>ThreadFoo()</strong>) that was running in a threads pool.<br />
In that moment I started to research why _chkstk() fails and my first track was to debug the stack overflows. I followed a <a target="blank" href="http://msdn.microsoft.com/en-us/library/ff540620(VS.85).aspx">MSDN debugging tutorial</a> and unfortunately I didn’t find something strange. I checked if the local stack variables are not so big in order to fill the ThreadFoo() function’s stack and it did not.<br />
Then a new study of ThreadFoo() function has followed in order to detect the internal functions calls that can fail in some circumstances. I stopped to some trace function calls and I studied deeply. Those trace functions where defined in an external debug class and each time when a new trace file was added it used an internal buffer (<strong>TCHAR szBuff[2048] = _T(&#8220;&#8221;);</strong>).<br />
The writing of this buffer was done using: <a target="blank" href="http://msdn.microsoft.com/en-us/library/ybk95axf(v=VS.80).aspx">swprintf()</a>. As we know this function is unsafe and is not recommended to use. As long as the content of these trace lines was dynamically build (in some cases those line may contain even dynamically build SQL queries that failed) then the length of these trace lines could be higher than 2048 bytes and then guess what: <strong>a stack corruption appears! UPS!</strong> The stack pointer will be corrupted (the classic stack overflow case).</p>
<p>So I have implemented and used the next macros:</p>
<pre>
#ifdef _UNICODE
#define usprintf(x, ...)	_snwprintf(x, _countof(x) - 1, ##__VA_ARGS__); x[_countof(x)-1] = 0
#else
#define usprintf(x, ...)	_snprintf(x, _countof(x) - 1, ##__VA_ARGS__); x[_countof(x)-1] = 0
#endif
</pre>
<p>Now, if we&#8217;re using the safe macro we will have no issues.</p>
<pre>
int x = 23;
TCHAR szMsg[2048] = {0};
usprintf(szMsg, L"Error: %d", x);
</pre>
<p>A safety alternative way to that buffer was the heap using but the heap access is not fast as the stack access so I preferred this approach (in a business application every milliseconds matters for the log system).<br />
After that fixed I met no other stack corruptions in ThreadFoo() and other code areas.</p>
<p>Even if the top of the call stack was _chkstk() this was not the function that failed. The error appeared because of that stack corruption and _chkstk() has just detected.</p>
<p><strong>Conclusion</strong><br />
If your code produces a stack overflow, then you have to rethink your design in right away:</p>
<li>If you see _chkstk() on the top of call stack, check if you have no stack corruptions &#8211; stack overflow.</li>
<li>Don&#8217;t try to manipulate the stack by yourself. The default 1MB stack size is basically enough</li>
<li>Allocate dynamically if you’re using big arrays</li>
<li>If you have recursive functions producing a stack overflow, re-write them using loops (a tip: it is a proven fact that any recursive functions can be programmed non-recursive)</li>
<p><strong>References</strong><br />
<a target="blank" href="http://msdn.microsoft.com/en-us/library/tdkhxaks.aspx" title="Set stack size">Set stack size</a><br />
<a target="blank" href="http://msdn.microsoft.com/en-us/library/ms686774(v=vs.85).aspx">Thread Stack Size</a><br />
<a target="blank" href="http://msdn.microsoft.com/en-us/library/ms648426(v=vs.85).aspx">_chkstk Routine</a><br />
<a target="blank" href="http://en.wikipedia.org/wiki/Stack_(data_structure)" title="Stack Wikipedia">Stack (data structure)</a><br />
<a target="blank" href="http://msdn.microsoft.com/en-us/library/ff540620.aspx">Debugging a Stack Overflow &#8211; tutorial</a><br />
<a target="blank" href="http://apocryph.org/2008/06/01/visual_c_apps_crashing_chkstk_under_load/">Visual C++ apps crashing in _chkstk() under load</a><br />
<a target="blank" href="http://blogs.msdn.com/b/fyuan/archive/2011/04/04/optimization-note-c-1-push-10h-pop-eax-call-chkstk.aspx">Optimization Note (C++) 1: push, pop, call _chkstk</a><br />
<a target="blank" href="http://www.sparknotes.com/cs/recursion/whatisrecursion/section1.html">What is Recursion?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2011/07/14/adventures-with-chkstk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pre vs. post  increment operator &#8211; benchmark</title>
		<link>http://silviuardelean.ro/2011/04/20/pre-vs-post-increment-operator/</link>
		<comments>http://silviuardelean.ro/2011/04/20/pre-vs-post-increment-operator/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 20:21:37 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[C++ 0X]]></category>
		<category><![CDATA[PPL]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=641</guid>
		<description><![CDATA[A recent <a href="https://twitter.com/#!/visualc/status/54050586378768384" target="blank">Visual C++ team’s comment on twitter.com</a> reminded me a hot topic that exists in C++ programming world: there is a long discussion of using pre versus post increment operators, specially, for iterators. Even me I was witness to a discussion like this. The discussion started from a <a href="http://www.codexpert.ro/forum/viewtopic.php?f=29&#038;t=112#p9823" target="blank">FAQ</a> written by me on www.codexpert.ro.

Base on that VC++ team’s tweet related to <a href="http://www.viva64.com/en/b/0093/" target="blank">viva64.com’s research</a> I decided to create my own benchmark base on single and multicore architectures. For those that don’t know Viva64 is a company specialized on Static Code Analysis. 
Starting from their project I extended the tested for other STL containers: <em>std::vector, std::list, std::map, and std::unordered_map</em> (VC++ 2010 hash table implementation).
For parallel core tests I used Microsoft's new technology called <a href="http://msdn.microsoft.com/en-us/library/dd492418.aspx" target="blank">Parallel Pattern Library</a>.
<a href="http://silviuardelean.ro/2011/04/20/pre-vs-post-increment-operator/">continue...</a>]]></description>
			<content:encoded><![CDATA[<p><strong>Compiler</strong>:   Visual C++ 2010<br />
<strong>Operating System</strong>: Windows 7 32bits<br />
<strong>Tested machine CPU</strong>: Intel core i3<br />
<strong>Download</strong>:   <a class="downloadlink" href="http://silviuardelean.ro/wp-content/plugins/download-monitor/download.php?id=4" title=" downloaded 74 times" >preVSpost (demo project) (74)</a></p>
<p>A recent <a href="https://twitter.com/#!/visualc/status/54050586378768384" target="blank">Visual C++ team’s comment on twitter.com</a> reminded me a hot topic that exists in C++ programming world: there is a long discussion of using pre versus post increment operators, specially, for iterators. Even me I was witness to a discussion like this. The discussion started from a <a href="http://www.codexpert.ro/forum/viewtopic.php?f=29&#038;t=112#p9823" target="blank">FAQ</a> written by me on www.codexpert.ro.</p>
<p>The reason of preferring pre increment operators is simple. For each post-increment operator a temporary object is needed.<br />
Visual C++ STL implementation looks similarly with next code:</p>
<pre>
_Myt_iter operator++(int)
{   // postincrement
  _Myt_iter _Tmp = *this;
  ++*this;
  return (_Tmp);
}
</pre>
<p>But for pre-increment operator implementation this temporary object is not needed anymore.</p>
<pre>
_Myt_iter&#038; operator++()
{   // preincrement
  ++(*(_Mybase_iter *)this);
  return (*this);
}
</pre>
<p>In the discussion that I mentioned above, somebody came with a <a href="http://pastebin.com/8GbgFLBw" target="blank">dummy application</a> and tried to prove that things have changed because of new compilers optimizations (the code exists in the attached file, too). This sample is too simple and far away to the real code. Normally the real code has more code line codes that eat CPU time even if you’re compiling with <strong>/O2</strong> settings (is obviously).<br />
Base on that VC++ team’s tweet related to <a href="http://www.viva64.com/en/b/0093/" target="blank">viva64.com’s research</a> I decided to create my own benchmark base on single and multicore architectures. For those that don’t know Viva64 is a company specialized on Static Code Analysis.<br />
Starting from their project I extended the tested for other STL containers: <em>std::vector, std::list, std::map, and std::unordered_map</em> (VC++ 2010 hash table implementation).<br />
For parallel core tests I used Microsoft&#8217;s new technology called <a href="http://msdn.microsoft.com/en-us/library/dd492418.aspx" target="blank">Parallel Pattern Library</a>.</p>
<p><strong>1.  How the tests were made</strong><br />
<strong>1.1.  Code stuff</strong><br />
In order to get execution time I used same timer as Viva64 team (with few changes). Each container instance was populated with 100000 elements of same random data. An effective computing function was repeated 10 times. Into this function some template functions are called for 300 times. The single core computing function contains loops like this:</p>
<pre>
for (size_t i = 0; i != Count; ++i)
{
   x += FooPre(arr);
}

// where FooPre looks like
template &lt;class T&gt;
size_t FooPre(const T &amp;arr)
{
  size_t sum = 0;

  for (auto it = arr.begin(); it != arr.end(); ++it)
    sum += *it;

  return sum;
}
</pre>
<p>For the parallel core computing the first simple for loop has changed in:</p>
<pre>
parallel_for (size_t(0), Count,
[&#038;cnt,&#038;arr] (size_t i) {
	cnt.local() += FooPre(arr);
});</pre>
<p>Where <strong><em>cnt</em></strong> is an instance of <a href="http://msdn.microsoft.com/en-us/library/dd492850.aspx" target="blank">combinable</a> class and the sum of partial computed elements is obtained by calling <strong>combine()</strong> method:</p>
<pre>cnt.combine(plus&lt;size_t&gt;());</pre>
<p>As you can see, the parallel_for function uses one of the new C++ standard features: a lambda function. This lambda function and the <strong>combinable</strong> class implements the so called parallel aggregation pattern and helps you to avoid the multithreaded common share resource issues. The code is executed on independent tasks. The reason that this approach is fast is that there is very little need for synchronization operations. Calculating the per-task local results uses no shared variables, and therefore requires no locks. The combine operation is a separate sequential step and also does not require locks.</p>
<p><strong>1.2.	Effective results</strong><br />
The tests were running on a Intel core i3 machine (4 cores) running Windows 7 on 32bits OS. I tested debug and release mode for single and multi cores computation. The test application was build in VC++ 2010 one of the first C++11 compliant.<br />
The OX axis represents the execution repeated times, and the OY axis means time in seconds. </p>
<p><strong>1.2.1.	Single core computation</strong><br />
<em><strong>Debug</strong></em><br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/04/serial-debug-graph.png" rel="lightbox[641]" title="serial-debug-graph"><img src="http://silviuardelean.ro/wp-content/uploads/2011/04/serial-debug-graph.png" alt="" title="serial-debug-graph" width="627" height="466" class="aligncenter size-full wp-image-660" /></a></p>
<p><em><strong>Release</strong></em><br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/04/serial-release-graph.png" rel="lightbox[641]" title="serial-release-graph"><img src="http://silviuardelean.ro/wp-content/uploads/2011/04/serial-release-graph.png" alt="" title="serial-release-graph" width="648" height="429" class="aligncenter size-full wp-image-661" /></a></p>
<p><strong>1.2.2.	Multi cores computation</strong><br />
As you know, multi core programming is the future. For C++ programmers Microsoft propose a very interesting library called Parallel Pattern Library.<br />
The overall goal is to decompose the problem into independent tasks that do not share data, while providing a sufficient number of tasks to occupy the number of cores available.</p>
<p>This is how it looks my task manager when the demo application runs in parallel mode.<br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/04/cpu-usage-2.png" rel="lightbox[641]" title="cpu-usage-2"><img src="http://silviuardelean.ro/wp-content/uploads/2011/04/cpu-usage-2.png" alt="" title="cpu-usage-2" width="605" height="161" class="aligncenter size-full wp-image-663" /></a><br />
Isn&#8217;t it nice comparing to a single core use? <img src='http://silviuardelean.ro/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p><em><strong>Debug</strong></em><br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/04/parallel-debug-graph.png" rel="lightbox[641]" title="parallel-debug-graph"><img src="http://silviuardelean.ro/wp-content/uploads/2011/04/parallel-debug-graph.png" alt="" title="parallel-debug-graph" width="676" height="415" class="aligncenter size-full wp-image-666" /></a><br />
<em><strong>Release</strong></em><br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/04/parallel-release-graph.png" rel="lightbox[641]" title="parallel-release-graph"><img src="http://silviuardelean.ro/wp-content/uploads/2011/04/parallel-release-graph.png" alt="" title="parallel-release-graph" width="668" height="457" class="aligncenter size-full wp-image-665" /></a></p>
<p><strong>1.2.3.	Speedup</strong><br />
<a href="http://en.wikipedia.org/wiki/Speedup" target="blank">Speedup</a> is an efficiency performance metric for a parallel algorithm comparing to a serial algorithm.</p>
<p><em><strong>Debug</strong></em><br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/04/speed-up-debug.png" rel="lightbox[641]" title="speed-up-debug"><img src="http://silviuardelean.ro/wp-content/uploads/2011/04/speed-up-debug.png" alt="" title="speed-up-debug" width="671" height="463" class="aligncenter size-full wp-image-670" /></a></p>
<p><em><strong>Release</strong></em><br />
<a href="http://silviuardelean.ro/wp-content/uploads/2011/04/speed-up-release.png" rel="lightbox[641]" title="speed-up-release"><img src="http://silviuardelean.ro/wp-content/uploads/2011/04/speed-up-release.png" alt="" title="speed-up-release" width="610" height="471" class="aligncenter size-full wp-image-672" /></a></p>
<p><em><strong>Conclusions:</strong></em><br />
The biggest differences appear in the debugging area where the pre-increment is “<em>the champion</em>”. <img src='http://silviuardelean.ro/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
According to these results I have to agree with Viva64 team. Even if the results are so close in release version I keep my opinion that using pre increment operator is preferred instead of post increment operators. We all know how long it takes the debug period and how important is every second that we win in long debugging days.</p>
<p>If you still have doubts in using pre-increment operator or you need a flexible way of switching this operators in your code you can easily implement some macros like these:</p>
<pre>
#define VECTOR_ITERATOR(type, var_iter)  std::vector&lt;type&gt;::iterator var_iter;
#define VECTOR_FOR(vect, var_iter)	for (var_iter = vect.begin(); var_iter != vect.end(); ++var_iter)</pre>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2011/04/20/pre-vs-post-increment-operator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Numeric type conversion to std::string and vice versa</title>
		<link>http://silviuardelean.ro/2011/01/15/numeric-type-conversion-to-string-and-vice-versa/</link>
		<comments>http://silviuardelean.ro/2011/01/15/numeric-type-conversion-to-string-and-vice-versa/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 16:25:40 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[string conversion]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=436</guid>
		<description><![CDATA[In our real applications we have to convert from strings to integer or to real variables and vice versa (<strong>double</strong>/<strong>float</strong>/<strong>int</strong> variable to <strong>std::string</strong>).
We can realize these conversions using C style CRT function or we can try C++ approach via <a href="http://en.wikipedia.org/wiki/Standard_Template_Library" target="blank">STL</a>.

<a href="http://silviuardelean.ro/2011/01/15/numeric-type-conversion-to-string-and-vice-versa/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/01/string2numeric.png" alt="" title="Continue to article" width="392" height="354" class="aligncenter size-full wp-image-586" /></a>
<a href="http://silviuardelean.ro/2011/01/15/numeric-type-conversion-to-string-and-vice-versa/">continue...</a>]]></description>
			<content:encoded><![CDATA[<p>In our real applications we have to convert from strings to integer or to real variables and vice versa (<strong>double</strong>/<strong>float</strong>/<strong>int</strong> variable to <strong>std::string</strong>).<br />
We can realize these conversions using C style CRT function or we can try C++ approach via <a href="http://en.wikipedia.org/wiki/Standard_Template_Library" target="blank">STL</a>.<br />
Unfortunately, current C standard libraries do not offer a complete support for any type of conversion. For instance, if we try to put an integer into a C++ string object (std::(w)string) using a well known function <strong>itoa()</strong> then we get next error:</p>
<pre>
  int x1 = 230;
  std::string s1;
  itoa(x1, s1, 10);
</pre>
<p><strong>// error C2664: &#8216;itoa&#8217; : cannot convert parameter 2 from &#8216;std::string&#8217; to &#8216;char *&#8217;</strong></p>
<p>A C style approach in order to avoid this error means using an intermediary buffer:</p>
<pre>
    int x1 = 230;
    std::string s1;
    char szBuff[64]={0};
    itoa(x1, szBuff, 10);
    s1 = szBuff;
</pre>
<p>Same story if we try to convert a <strong>std::string</strong> to an <strong>int</strong>:</p>
<pre>
  std::string s3 = "442";
  int x3 = atoi(s3);
</pre>
<p><strong>// error C2664: &#8216;atoi&#8217; : cannot convert parameter 1 from &#8216;std::string&#8217; to &#8216;const char *&#8217;</strong></p>
<p>In this case we can use <strong>c_str()</strong> in order to return a constant pointer to char.</p>
<pre>int x3 = atoi(s3.c_str());</pre>
<p>An elegant way to get rid of such problems is to build two conversion function that use templates and C++ streams.<br />
Base on this idea, I created a <strong>Sting2Numeric</strong> class that contains two static methods: <strong>Type2String()</strong> and <strong>String2Type()</strong>.</p>
<pre>
class String2Numeric
{
   public:

	template &lt;class TypeT&gt;
	static xstring Type2String(TypeT x)
	{
		xostringstream o;
		if (!(o &lt;&lt; x))
			throw BadConversion(&quot;Type2String(TypeT)&quot;);

		return o.str();
	} 

	template &lt;class TypeT&gt;
	static TypeT   String2Type(const xstring&amp; s)
	{
		xistringstream i(s);
		TypeT x;
		if (!(i &gt;&gt; x))
			throw BadConversion(&quot;String2Type(TypeT)&quot;);

		return x;
	}
};
</pre>
<p>where <strong>BadConvertion</strong> is a <strong>std::runtime_error</strong>&#8216;s derived class.</p>
<pre>
class BadConversion : public std::runtime_error {
public:
	BadConversion(const std::string&#038; s)
		: std::runtime_error(s)
	{ }
};</pre>
<p>Because of ANSI and UNICODE project’s compatibility I defined few macros:</p>
<pre>
#ifdef _UNICODE
	#define	xstring			std::wstring
	#define	xostringstream	std::wostringstream
	#define	xistringstream	std::wistringstream
#else
	#define	xstring			std::string
	#define	xostringstream	std::ostringstream
	#define	xistringstream	std::istringstream
#end
</pre>
<p>Because of this compatibility I strongly recommend using a <strong>xstring</strong> alias instead of <strong>std::wstring</strong> or <strong>std::string</strong>.<br />
When you want to convert an <strong>int</strong>, <strong>float</strong>, <strong>double</strong>, or other numerical type to a <strong>xstring</strong> in a C++ style you can use the <strong>Type2String()</strong> function. Vice versa, if you want to convert a <strong>xstring</strong> to these types you can use <strong>String2Type()</strong>.</p>
<p>In order to avoid possible thrown exception I recommend to you using a try catch block whenever you’re using these functions. I prefer using <strong>xstring</strong> for <strong>string/wstring</strong> variables definition, too.<br />
Here is a sample of using this class:</p>
<pre>
double y1 = 0.2312, y2 = 1.0123;
xstring s1 , s2;

try
{
	s1 = String2Numeric::Type2String&lt;double&gt;(y1);
	s2 = String2Numeric::Type2String&lt;int&gt;(x2);

	#ifdef _UNICODE
		xstring s3(L&quot;43.52&quot;);
	#else
		xstring s3(&quot;43.52&quot;);
	#endif

	x2 = String2Numeric::String2Type&lt;int&gt;(s3);
	y2 = String2Numeric::String2Type&lt;double&gt;(s3);
}
catch (BadConversion &amp;eBC)
{
  std::cout &lt;&lt; &quot;An exception has been thrown: &quot; &lt;&lt; eBC.what() &lt;&lt; std::endl;
}
</pre>
<p>The <strong>String2Numeric</strong> class can be extended. For instance, if the conversion throw an error then you can add detailed information in the exception message.</p>
<p>Download <a class="downloadlink" href="http://silviuardelean.ro/wp-content/plugins/download-monitor/download.php?id=3" title="Version1.0 downloaded 79 times" >String2Numeric (79)</a> class.</p>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2011/01/15/numeric-type-conversion-to-string-and-vice-versa/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flexible changes for product version properties &#8211; Visual C++ binaries</title>
		<link>http://silviuardelean.ro/2011/01/09/flexible-changes-for-product-version-properties-visual-c-binaries/</link>
		<comments>http://silviuardelean.ro/2011/01/09/flexible-changes-for-product-version-properties-visual-c-binaries/#comments</comments>
		<pubDate>Sun, 09 Jan 2011 14:40:31 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[Articles & Tutorials]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[WinAPI]]></category>
		<category><![CDATA[product version]]></category>
		<category><![CDATA[resources]]></category>
		<category><![CDATA[Visual Studio IDE]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=532</guid>
		<description><![CDATA[Manually editing of binaries version in the resource editor of Visual Studio IDE is not a viable solution. If we have dozens of projects in our solution, then for each kit building we should need manual resources file edit. Otherwise, we can use a special tool that does this thing for us. 
Unfortunately this approach is not the most flexible and could fail.

For our flexible binaries properties changes and in order to avoid manual edit for each rebuild we can create and include a header file (<strong>version.h</strong>) that contains some constants of <strong>product version</strong> and <strong>file version</strong> of our project  (<strong>.rc</strong> files).

We have to include only these constants into this file (<strong>version.h</strong>):
    <strong>#define PRODUCT_VERSION      4.3.2.198
    #define PRODUCT_VERSION_STR  "4.3.2.198"</strong>
Then, for each <strong>.rc</strong> file wherever we have <strong>FileVersion</strong> and <strong>ProductVersion</strong> we have to use this constants. 
When we will build a new kit, we have to change only these constants and then to start the kit building process. Everything is fine until we add new controls in our projects resource files.  Then, because of Visual Studio IDE automation we can get an unlikely surprise: the <strong>FileVersion</strong> and the <strong>ProductVersion</strong> properties could be reset to 1.0.0.0.

<a href="http://silviuardelean.ro/2011/01/09/flexible-changes-of-product-version-properties-visual-c-binaries/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/01/auto-product-version.png" alt="" title="Continue to article" width="368" height="507" class="aligncenter size-full wp-image-545" /></a>

In order to avoid this issue and edit the version only in a single place I propose the following <a href="http://silviuardelean.ro/2011/01/09/flexible-changes-of-product-version-properties-visual-c-binaries/">workaround</a>.]]></description>
			<content:encoded><![CDATA[<p>Manually editing of binary files version in the resource editor of Visual Studio IDE is not a viable solution. If we have dozens of projects in our solution, then for each kit building we should need manual resources file edit. Otherwise, we can use a special tool that does this thing for us.<br />
Unfortunately this approach is not the most flexible and could fail.</p>
<p>For our flexible binaries properties changes and in order to avoid manual edit for each rebuild we can create and include a header file (<strong>version.h</strong>) that contains some constants of <strong>product version</strong> and <strong>file version</strong> of our project  (<strong>.rc</strong> files).</p>
<p>We have to include only these constants into this file (<strong>version.h</strong>):</p>
<pre>
    #define PRODUCT_VERSION      4.3.2.198
    #define PRODUCT_VERSION_STR  "4.3.2.198"</pre>
<p>Then, for each <strong>.rc</strong> file wherever we have <strong>FileVersion</strong> and <strong>ProductVersion</strong> we have to use this constants.<br />
When we will build a new kit, we have to change only these constants and then to start the kit building process. Everything is fine until we add new controls in our projects resource files.  Then, because of Visual Studio IDE automation we can get an unlikely surprise: the <strong>FileVersion</strong> and the <strong>ProductVersion</strong> properties could be reset to 1.0.0.0.</p>
<p>In order to avoid this issue and edit the version only in a single place I propose the following workaround:</p>
<li>Create  a <strong>version.h</strong> header file that have to contain these constants only (as on top). I should recommend to create it into the root solution in order of being easy included in all the projects.</li>
<li>Include this file in the project you need to use.</il>
<li>Use a text editor (ex. notepad.exe) and include next code section at the end of <strong>.rc2</strong> resource file of your project (<strong>res\your_project.rc2</strong>) – this section contains the include <strong>version.h</strong> file section, too.</li>
<pre>
// Neutral resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
#ifdef _WIN32
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Version
//

#include &quot;..\version.h&quot;

VS_VERSION_INFO VERSIONINFO
 FILEVERSION PRODUCT_VERSION
 PRODUCTVERSION PRODUCT_VERSION
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK &quot;StringFileInfo&quot;
    BEGIN
        BLOCK &quot;040904e4&quot;
        BEGIN
            VALUE &quot;CompanyName&quot;, &quot;TODO: &lt;Company name&gt;&quot;
            VALUE &quot;FileDescription&quot;, &quot;TODO: &lt;File description&gt;&quot;
            VALUE &quot;FileVersion&quot;, PRODUCT_VERSION_STR
            VALUE &quot;InternalName&quot;, &quot;testResources.exe&quot;
            VALUE &quot;LegalCopyright&quot;, &quot;TODO: (c) &lt;Company name&gt;.  All rights reserved.&quot;
            VALUE &quot;OriginalFilename&quot;, &quot;your_project.exe&quot;
            VALUE &quot;ProductName&quot;, &quot;TODO: &lt;Product name&gt;&quot;
            VALUE &quot;ProductVersion&quot;, PRODUCT_VERSION_STR
        END
    END
    BLOCK &quot;VarFileInfo&quot;
    BEGIN
        VALUE &quot;Translation&quot;, 0x409, 1252
    END
END
#endif    // Neutral resources
/////////////////////////////////////////////////////////////////////////////
</pre>
<li>Edit “<em>040904e4</em>” block code with same data as if we should edit in a resources editor and use the <strong>version.h</strong>&#8216;s file defined constants. As you can see in my example, for the <strong>FileVersion</strong> and <strong>ProductVersion</strong> properties I use my <strong>version.h</strong> constants. These properties will not be edited anymore.</li>
<li>Delete “<em>// Version</em>” section from default resource file <strong>your_project.rc</strong> (including comments &#8211; recommended).</li>
<li>Insert next lines into <strong>your_project.rc</strong> file after &#8220;<strong>3 TEXTINCLUDE BEGIN</strong>&#8221; and before &#8220;<strong>#define _AFX_NO_SPLITTER_RESOURCES\r\n</strong>&#8220;:</li>
<pre>   "\r\n"
   "#include ""res\\your_project.rc2""\r\n"
   "\0"</pre>
<p>That code block looks like this:</p>
<pre>
3 TEXTINCLUDE
BEGIN
    "\r\n"
    "#include ""res\\your_project.rc2""\r\n"
    "\0"
    "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
    "#define _AFX_NO_OLE_RESOURCES\r\n"
    "#define _AFX_NO_TRACKER_RESOURCES\r\n"
    "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
    "\r\n"
    "#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
    "LANGUAGE 9, 1\r\n"
    "#pragma code_page(1252)\r\n"
    "#include ""res\\your_project.rc2""  // non-Microsoft Visual C++ edited resources\r\n"
    "#include ""afxres.rc""     // Standard components\r\n"
    "#endif\r\n"
    "\0"
END
</pre>
<p>Don’t forget to edit <strong>.rc2</strong> file name with the right file name of your project.</p>
<li>In <strong>your_project.rc</strong> file the section “<em>// Generated from the TEXTINCLUDE 3 resource.</em>” have to contain only next declaration:</li>
<pre>#include "res\your_project.rc2"</pre>
<p>The rest of the section’s lines have to be deleted.</p>
<li>We save both resources files: <strong>your_project.rc</strong> and <strong>your_project.rc2</strong>.</li>
<li>Rebuild the project and check the new generated binary properties. In the <strong>FileVersion</strong> we will have the major version (in my case <strong>4.0.0.0</strong>) and in <strong>ProductVersion</strong> we have the current build version (<strong>4.3.2.198</strong>).</li>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2011/01/auto-product-version.png" rel="lightbox[532]" title="auto-product-version"><img src="http://silviuardelean.ro/wp-content/uploads/2011/01/auto-product-version.png" alt="" title="auto-product-version" width="368" height="507" class="aligncenter size-full wp-image-545" /></a></p>
<p><strong>Observations</strong><br />
Once you apply these steps, the product version properties will not possible from the Visual Studio IDE resource editor, anymore (only as edit text file or an external text editor). If we didn’t define something special in our project’s <strong>String Table</strong> we will see only <strong>IDS_ABOUTBOX</strong>.</p>
<a class="downloadlink" href="http://silviuardelean.ro/wp-content/plugins/download-monitor/download.php?id=2" title=" downloaded 99 times" >Demo application - AutoProductVersion (99)</a>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2011/01/09/flexible-changes-for-product-version-properties-visual-c-binaries/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Simple Pictures Unifier &#8211; first version</title>
		<link>http://silviuardelean.ro/2011/01/04/simple-pictures-unifier-first-version/</link>
		<comments>http://silviuardelean.ro/2011/01/04/simple-pictures-unifier-first-version/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 08:40:21 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[freeware]]></category>
		<category><![CDATA[photos organizator]]></category>
		<category><![CDATA[pictures organizator]]></category>
		<category><![CDATA[Simple Pictures Unifier]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=439</guid>
		<description><![CDATA[Have you just returned from vacation and you have a lot of pictures? You just downloaded your taken pictures and you got your friends pictures, too? Then, probably, the pictures are scattered, with a random order in your computer.
Would you like seeing pictures from all sources in order of events happening?
If so, try to sort your photos using <a href="http://silviuardelean.ro/applications/simple-pictures-unifier/">Simple Pictures Unifier</a> tool! :)

<a href="http://silviuardelean.ro/applications/simple-pictures-unifier/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/01/SPU-screenshot-3.png" alt="Simple Pictures Unifier application" title="Simple Pictures Unifier application" width="722" height="612" class="aligncenter size-full wp-image-452" /></a>

Please, feel free to add comments, suggestions or bugs reports to this application.
Any constructive feedback is sincerely appreciated. Thanks you!]]></description>
			<content:encoded><![CDATA[<p>Have you just returned from vacation and you have a lot of pictures? You just downloaded your taken pictures and you got your friends pictures, too? Then, probably, the pictures are scattered, with a random order in your computer.<br />
Would you like seeing pictures from all sources in order of events happening?<br />
If so, try to sort your photos using <a href="http://silviuardelean.ro/applications/simple-pictures-unifier/">Simple Pictures Unifier</a> tool! <img src='http://silviuardelean.ro/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://silviuardelean.ro/applications/simple-pictures-unifier/"><img src="http://silviuardelean.ro/wp-content/uploads/2011/01/SPU-screenshot-3.png" alt="Simple Pictures Unifier application" title="Simple Pictures Unifier application" width="722" height="612" class="aligncenter size-full wp-image-452" /></a></p>
<p>Please, feel free to add comments, suggestions or bugs reports to this application.<br />
Any constructive feedback is sincerely appreciated. Thanks you!</p>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2011/01/04/simple-pictures-unifier-first-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>File size fast detection</title>
		<link>http://silviuardelean.ro/2010/11/23/file-size-fast-detection/</link>
		<comments>http://silviuardelean.ro/2010/11/23/file-size-fast-detection/#comments</comments>
		<pubDate>Tue, 23 Nov 2010 22:52:50 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[WinAPI]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[CRT]]></category>
		<category><![CDATA[FAQ]]></category>
		<category><![CDATA[files]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=393</guid>
		<description><![CDATA[Many times in our job, we need to work with files and need to know file properties. 
One of the most important properties is <strong>file size</strong>. Of course, there are a lot of API that allows finding this property, but most of them needs additional file operations: open file, find file size and close file. 

<a href="http://silviuardelean.ro/2010/11/23/file-size-fast-detection/"><img src="http://silviuardelean.ro/wp-content/uploads/2010/11/file-size-fast-detection.png" alt="" title="Continue to article..." width="580" height="193" class="aligncenter size-full wp-image-631" /></a>

<a href="http://silviuardelean.ro/2010/11/23/file-size-fast-detection/">continue...</a>]]></description>
			<content:encoded><![CDATA[<p>Many times in our job, we need to work with files and need to know file properties.<br />
One of the most important properties is <strong>file size</strong>. Of course, there are a lot of API that allows finding this property, but most of them needs additional file operations: open file, find file size and close file. </p>
<p>A direct and fast way in order to detect the file size without these operations means the CRT run-time library’s function <a href="http://msdn.microsoft.com/en-us/library/14h5k7ff(VS.71).aspx" target="blank">_tstat64()</a> and stuff.</p>
<p>In the header file or on .cpp file please add next macros definitions:</p>
<pre>
#define __S_ISTYPE(mode, mask)  (((mode) &#038; _S_IFMT) == (mask))
#define S_ISDIR(mode)    __S_ISTYPE((mode), _S_IFDIR)
</pre>
<p>Then, write next function:</p>
<pre>
long long GetFileSizeFast(const TCHAR *szFilePath)
{
	if (!szFilePath || !szFilePath[0] || !PathFileExists(szFilePath))
		return -1;

	long long nSize = -1;
	struct __stat64 buf;
	nSize  = (_tstat64( szFilePath, &#038;buf ) == 0) ? buf.st_size : -1;
	if (S_ISDIR(buf.st_mode)) nSize = -1;

	return nSize;
}</pre>
<p>If you&#8217;re using WinAPI there is an even faster way in order to get file size.</p>
<pre>long long GetFileSizeFastest(const TCHAR* szFilePath)
{
	if (!szFilePath || !szFilePath[0] || !PathFileExists(szFilePath))
		return -1;

	WIN32_FIND_DATA sFileData;
	HANDLE hFind = FindFirstFile(szFilePath, &#038;sFileData);
	if (hFind == INVALID_HANDLE_VALUE)
		return -1;

	FindClose(hFind);

	return  (sFileData.nFileSizeHigh * (MAXDWORD+1LL)) + sFileData.nFileSizeLow;
}</pre>
<p>Finally, call these functions wherever you need. </p>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2010/11/23/file-size-fast-detection/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Hungry boy &#8211; Google Chrome 5</title>
		<link>http://silviuardelean.ro/2010/09/18/hungry-boy-google-chrome/</link>
		<comments>http://silviuardelean.ro/2010/09/18/hungry-boy-google-chrome/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 21:24:31 +0000</pubDate>
		<dc:creator>Silviu Ardelean</dc:creator>
				<category><![CDATA[IT funny stuff]]></category>
		<category><![CDATA[Other stuff]]></category>
		<category><![CDATA[funny it]]></category>
		<category><![CDATA[google chome]]></category>

		<guid isPermaLink="false">http://silviuardelean.ro/?p=355</guid>
		<description><![CDATA[My currently default bowser is Google Chrome. I use it more then 90% browsing time. I like it because is launching so fast, is a secure broswer, respects major W3C standards and has an interesting application architecture. Each tab is an independent process and if appears some troubles in one tab, you can stop that process only, without loosing other Chrome's tabs data.

Unfortunately, two weeks ago, watching few slides presentations over slideshare.net I was shocked by a Windows message on my laptop: "<em><strong>Your computer is low on memory. Save your files and close these programs: Google Chrome.</strong></em>"

<a href="http://silviuardelean.ro/2010/09/18/hungry-boy-google-chrome/">continue...</a>]]></description>
			<content:encoded><![CDATA[<p>My currently default bowser is Google Chrome. I use it more then 90% of my browsing time. I like it because it&#8217;s launching so fast, is a secure broswer, respects major W3C standards and has an interesting application architecture. Each tab is an independent process and if appears some troubles in one process, you can stop that process only, without loosing other Chrome&#8217;s tabs (processes) data.</p>
<p>Unfortunately, two weeks ago, watching few slides presentations over slideshare.net I was shocked by a Windows message on my laptop (Windows 7 Ultimate x64 OS): &#8220;<em><strong>Your computer is low on memory. Save your files and close these programs: Google Chrome.</strong></em>&#8221;<br />
<strong>What the hack?!</strong></p>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2010/09/full_memory_with_Windows_msg.png" target="blank" rel="lightbox[355]" title="full_memory_with_Windows_msg"><img src="http://silviuardelean.ro/wp-content/uploads/2010/09/full_memory_with_Windows_msg.png" alt="Windows special MessageBox" title="full_memory_with_Windows_msg" width="968" height="702" class="aligncenter size-full wp-image-359" /></a></p>
<p>I closed that window and I investigated Task Manager in order to detect witch process was using my memory.<br />
I was socked again when I saw that one Chrome process was using even 701 MB!</p>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2010/09/full_memory-never seen this.png" target="blank" rel="lightbox[355]" title="full_memory- never seen this"><img src="http://silviuardelean.ro/wp-content/uploads/2010/09/full_memory-never seen this.png" alt="huge used memory" title="full_memory- never seen this" width="548" height="594" class="aligncenter size-full wp-image-363" /></a></p>
<p>Briliant!</p>
<p><a href="http://silviuardelean.ro/wp-content/uploads/2010/09/full_memory_graph.png" target="blank" rel="lightbox[355]" title="full_memory_graph"><img src="http://silviuardelean.ro/wp-content/uploads/2010/09/full_memory_graph.png" alt="Memory graph" title="full_memory_graph" width="435" height="615" class="aligncenter size-full wp-image-365" /></a></p>
<p>The main Google Chrome process had 13 tabs: 8 tabs contained slideshare.net presentations, one with twitter.com and the rest normal web pages.</p>
]]></content:encoded>
			<wfw:commentRss>http://silviuardelean.ro/2010/09/18/hungry-boy-google-chrome/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

