<?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/"
	>

<channel>
	<title>çetin's blog</title>
	<atom:link href="http://www.cetinkoca.com/blog/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cetinkoca.com/blog</link>
	<description>pronounced as chat-in ;)</description>
	<pubDate>Thu, 02 Apr 2009 19:32:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>EvilInput(TM)</title>
		<link>http://www.cetinkoca.com/blog/index.php/2009/04/evilinputtm/</link>
		<comments>http://www.cetinkoca.com/blog/index.php/2009/04/evilinputtm/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 19:28:50 +0000</pubDate>
		<dc:creator>çetin</dc:creator>
		
		<category><![CDATA[Technical Articles]]></category>

		<category><![CDATA[DirectInput]]></category>

		<category><![CDATA[input]]></category>

		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://www.cetinkoca.com/blog/?p=93</guid>
		<description><![CDATA[DirectInput has been one of the commonly used components of game engines, especially the ones developed by hobbyists which easily cloaks the fact that it&#8217;s actually quite deprecated.
I believe that the reason DirectInput is so commonly used is not its ease of use. It is rather the amount of tutorials available on the Internet and [...]]]></description>
			<content:encoded><![CDATA[<p>DirectInput has been one of the commonly used components of game engines, especially the ones developed by hobbyists which easily cloaks the fact that it&#8217;s actually quite deprecated.<span id="more-93"></span></p>
<p>I believe that the reason DirectInput is so commonly used is not its ease of use. It is rather the amount of tutorials available on the Internet and also the amount of ready-to-use code written on top of DirectInput.</p>
<p>It has quite a bit of evil running under the hood, though. First of all, DirectInput creates a second thread to read data from input devices and process it. Having a separate thread for input processing running in the background may not be significant, which is relative to the application. It nevertheless has an unnecessary overhead. Another important point is that DirectInput is low level. But we want low level stuff when developing 3D applications, right? That&#8217;s not always true. DirectInput, for example, lacks the following features because it is such a low level API:</p>
<ul>
<li>It does not apply pointer ballistics (i.e. pointer acceleration)</li>
<li>It does not process shifted input, such that you need to process input like &#8220;&lt;shift&gt; + a&#8221; so that it is interpreted as &#8220;A&#8221;.</li>
<li>It does not detect the state of caps lock but only detects whether caps lock key was pressed.</li>
<li>It cannot give you the absolute coordinates of the cursor. Instead you get a bunch of delta coordinates and have to process these along with the initial coordinates to compute the absolute coordinates at a given time.</li>
<li>It does not support key maps other than US English.</li>
</ul>
<p>Some of the issues mentioned above may not sound as serious to you but they are indeed DirectInput issues. All of the features mentioned above are available when you handle standard Win32 input messages. The reason DirectInput doesn&#8217;t have these is because they are processed by the operating system at a higher-level layer than that of DirectInput. If you would like to spend time and implement such stuff in your application be my guest! Yeah, I didn&#8217;t think so either. I don&#8217;t even mention that using DirectInput usually requires considerably more code to get things working because of the low-level stuff.</p>
<p>Even <a href="http://msdn.microsoft.com/en-us/library/bb206183.aspx" target="_blank">Microsoft</a> states that DirectInput offers no advantages whatsoever in the general case and its use should be avoided:</p>
<blockquote><p>Overall, using DirectInput offers no advantages when reading data from mouse or keyboard devices, and the use of DirectInput in these scenarios is discouraged.</p></blockquote>
<p>I confess that I have been using an input system based on DirectInput for years, mainly because of the aforementioned reasons, that is the availability of tutorials and code around. I actually implemented it like 5 years ago and did not want to spend time on reimplementing it without DirectInput, until now. I think I&#8217;ll do it sometime soon.</p>
<p>To sum up, try to stay away from DirectInput unless you need exotic features like force feedback or you absolutely need to support special DirectInput hardware. It probably won&#8217;t kill your application but what doesn&#8217;t kill your application may not turn out to make it stronger.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cetinkoca.com/blog/index.php/2009/04/evilinputtm/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Regular Mess</title>
		<link>http://www.cetinkoca.com/blog/index.php/2009/03/regular-mess/</link>
		<comments>http://www.cetinkoca.com/blog/index.php/2009/03/regular-mess/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 22:51:26 +0000</pubDate>
		<dc:creator>çetin</dc:creator>
		
		<category><![CDATA[Bits & Pieces]]></category>

		<category><![CDATA[Funny]]></category>

		<category><![CDATA[Regex]]></category>

		<category><![CDATA[Regular expressions]]></category>

		<category><![CDATA[RFC 822]]></category>

		<guid isPermaLink="false">http://www.cetinkoca.com/blog/?p=78</guid>
		<description><![CDATA[Regular expressions can actually be quite messy. Don&#8217;t you think so? Well, think not before you see this&#8230;
Below is a regular expression used to validate email addresses according to the RFC 822 grammar. I just encountered this while browsing web today. Seriously, what the hell?
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()&#60;&#62;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+&#124;\Z&#124;(?=[\["()&#60;&#62;@,;:\\".\[\]]))&#124;&#8221;(?:[^\"\r\\]&#124;\\.&#124;(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&#60;&#62;@,;:\\".\[\] \000-\031]+(?:(?:(
?:\r\n)?[ \t])+&#124;\Z&#124;(?=[\["()&#60;&#62;@,;:\\".\[\]]))&#124;&#8221;(?:[^\"\r\\]&#124;\\.&#124;(?:(?:\r\n)?[
\t]))*&#8221;(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()&#60;&#62;@,;:\\".\[\] [...]]]></description>
			<content:encoded><![CDATA[<p>Regular expressions can actually be quite messy. Don&#8217;t you think so? Well, think not before you see this&#8230;<span id="more-78"></span></p>
<p>Below is a <a href="http://ex-parrot.com/~pdw/Mail-RFC822-Address.html" target="_blank">regular expression</a> used to validate email addresses according to the <a href="http://www.ietf.org/rfc/rfc0822.txt?number=822" target="_blank">RFC 822</a> grammar. I just encountered this while browsing web today. Seriously, what the hell?</p>
<blockquote><p><code>(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]<br />
)+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:<br />
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(<br />
?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[<br />
\t]))*&#8221;(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\0<br />
31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\<br />
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+<br />
(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:<br />
(?:\r\n)?[ \t])*))*|(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z<br />
|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)<br />
?[ \t])*)*\&lt;(?:(?:\r\n)?[ \t])*(?:@(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\<br />
r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[<br />
\t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)<br />
?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t]<br />
)*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[<br />
\t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*<br />
)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]<br />
)+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)<br />
*:(?:(?:\r\n)?[ \t])*)?(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+<br />
|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r<br />
\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:<br />
\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t<br />
]))*&#8221;(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031<br />
]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](<br />
?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?<br />
:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?<br />
:\r\n)?[ \t])*))*\&gt;(?:(?:\r\n)?[ \t])*)|(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?<br />
:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?<br />
[ \t]))*&#8221;(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()&lt;&gt;@,;:\\".\[\]<br />
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|<br />
\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;<br />
@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;<br />
(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t]<br />
)*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\<br />
".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?<br />
:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[<br />
\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()&lt;&gt;@,;:\\".\[\] \000-<br />
\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(<br />
?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t])*)*\&lt;(?:(?:\r\n)?[ \t])*(?:@(?:[^()&lt;&gt;@,;<br />
:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([<br />
^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\"<br />
.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\<br />
]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\<br />
[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\<br />
r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\]<br />
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]<br />
|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()&lt;&gt;@,;:\\".\[\] \0<br />
00-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\<br />
.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,<br />
;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?<br />
:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*<br />
(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".<br />
\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[<br />
^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]<br />
]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\&gt;(?:(?:\r\n)?[ \t])*)(?:,\s*(<br />
?:(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\<br />
".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t])*)(?:\.(?:(<br />
?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[<br />
\["()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t<br />
])*))*@(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t<br />
])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?<br />
:\.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|<br />
\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:<br />
[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\<br />
]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t])*)*\&lt;(?:(?:\r\n)<br />
?[ \t])*(?:@(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["<br />
()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)<br />
?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;<br />
@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[<br />
\t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,<br />
;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t]<br />
)*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\<br />
".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?<br />
(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()&lt;&gt;@,;:\\".<br />
\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:<br />
\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[<br />
"()&lt;&gt;@,;:\\".\[\]]))|&#8221;(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*&#8221;(?:(?:\r\n)?[ \t])<br />
*))*@(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])<br />
+|\Z|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\<br />
.(?:(?:\r\n)?[ \t])*(?:[^()&lt;&gt;@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z<br />
|(?=[\["()&lt;&gt;@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\&gt;(?:(<br />
?:\r\n)?[ \t])*))*)?;\s*)</code></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.cetinkoca.com/blog/index.php/2009/03/regular-mess/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bit Fields</title>
		<link>http://www.cetinkoca.com/blog/index.php/2009/03/bit-fields/</link>
		<comments>http://www.cetinkoca.com/blog/index.php/2009/03/bit-fields/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 20:29:26 +0000</pubDate>
		<dc:creator>çetin</dc:creator>
		
		<category><![CDATA[Tips & Tricks]]></category>

		<category><![CDATA[Bit fields]]></category>

		<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://www.cetinkoca.com/blog/?p=56</guid>
		<description><![CDATA[Bit fields are probably one of the least popular language features of C/C++. By using bit fields the programmer can precisely define how many bits are occupied by each member of a struct or class. The syntax for bit fields follows:

struct Time
{
	unsigned int pm     : 1;
	unsigned int hour   : [...]]]></description>
			<content:encoded><![CDATA[<p>Bit fields are probably one of the least popular language features of C/C++. By using bit fields the programmer can precisely define how many bits are occupied by each member of a <code>struct</code> or <code>class</code>.<span id="more-56"></span> The syntax for bit fields follows:</p>
<pre class="brush: cpp">
struct Time
{
	unsigned int pm     : 1;
	unsigned int hour   : 4;
	unsigned int minute : 6;
};
</pre>
<p>The member field called <code>pm</code> of the <code>struct Time</code> above occupies only 1-bit, <code>hour</code> occupies 4-bits and <code>minute</code> occupies 6-bits.</p>
<p>Note that the members specified as a bit-field are always treated as integers, so you can omit the keyword <code>int</code> from the definition as follows:</p>
<pre class="brush: cpp">
struct Time
{
	unsigned pm     : 1;
	unsigned hour   : 4;
	unsigned minute : 6;
};
</pre>
<p>Bit fields are accessed just as any other member:</p>
<p><code>
<pre class="brush: cpp">
int main()
{
	Time time;
	time.pm = true;
	time.hour = 10;
	time.minute = 22;

	printf(&quot;The time is %d:%d %sn&quot;,
		time.hour, time.minute, time.pm ? &quot;PM&quot; : &quot;AM&quot;);

	return 0;
}
</pre>
<p></code></p>
<p>Bit fields are actually useful for:</p>
<ul>
<li>Packing several objects into one or more bytes, hence precise control over memory occupation in terms of bits</li>
<li> Creating structs suitable for reading data from, ans possibly writing data to, external file formats as well as transmitting data over network connections</li>
</ul>
<p>Although it is unlikely that you would need to use bit fields in your program, if you ever do so make sure you pay attention to the following:</p>
<ul>
<li>Portability issues</li>
<li>Thread-synchronization issues</li>
</ul>
<p>I will not go into the details here. If you would like to know more about bit fields check following links:</p>
<p><strong>msdn:</strong> <a href="http://msdn.microsoft.com/en-us/library/yszfawxh.aspx" target="_blank">C Bit Fields</a><br />
<strong>msdn:</strong> <a href="http://msdn.microsoft.com/en-us/library/ewwyfdbe.aspx" target="_blank">C++ Bit Fields</a><br />
<strong>Wikipedia:</strong> <a href="http://en.wikipedia.org/wiki/Bit_field" target="_blank">Bit field</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cetinkoca.com/blog/index.php/2009/03/bit-fields/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Java is so slow&#8230;</title>
		<link>http://www.cetinkoca.com/blog/index.php/2009/03/java-is-so-slow/</link>
		<comments>http://www.cetinkoca.com/blog/index.php/2009/03/java-is-so-slow/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 23:25:15 +0000</pubDate>
		<dc:creator>çetin</dc:creator>
		
		<category><![CDATA[Bits & Pieces]]></category>

		<category><![CDATA[allocation]]></category>

		<category><![CDATA[C/C++]]></category>

		<category><![CDATA[deallocation]]></category>

		<category><![CDATA[garbage collector]]></category>

		<category><![CDATA[heap]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[JVM]]></category>

		<category><![CDATA[malloc]]></category>

		<category><![CDATA[performance]]></category>

		<category><![CDATA[stack]]></category>

		<guid isPermaLink="false">http://www.cetinkoca.com/blog/?p=21</guid>
		<description><![CDATA[&#8230; you would think. Maybe not, but many people seem to agree with that. One interesting fact is that, though, Java&#8217;s allocations are much faster than classic malloc allocations. This is due to the highly optimized nature of allocation in modern JVMs and the way they handle heap allocations and deallocations. Generational collectors is one of [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; you would think. Maybe not, but many people seem to agree with that. One interesting fact is that, though, Java&#8217;s allocations are much faster than classic malloc allocations.<span id="more-21"></span> This is due to the highly optimized nature of allocation in modern JVMs and the way they handle heap allocations and deallocations. <a href="http://recherche.ircam.fr/equipes/repmus/Rapports/PeterHanappe99/ch1/node3.html" target="_blank">Generational collectors</a> is one of these techniques:</p>
<p> </p>
<blockquote><p>Generational collectors try to benefit from the empirically observed property that most allocated objects live for a very short time, while a small percentage of them live much longer. If an object survives one collection, chances are it will survive many collections. If the collector copies objects or compacts the heap, these long lived objects are copied over and over again. Generational techniques split the heap into several sub-heaps and segregates the objects in the sub-heaps according to their age. New objects are allocated in the first generation sub-heap. When the application runs out of memory, only the first generation sub-heap is scanned. The objects that survive one or more collections are moved to the second generation heap. If most objects are indeed short-lived, most of the first generation heap is freed and few objects need copying to the second generation heap. The older generation sub-heaps are scanned less frequently. Since smaller fragments of the heap are scanned and proportionally more storage space is recovered, the overall efficiency of the garbage collector improves.</p></blockquote>
<p> </p>
<p>Memory allocations are certainly just one aspect of application performance, and Java is still slow for performance-critical applications. Also don&#8217;t forget that programming languages like C and C++ still wins since most of the objects are allocated on the stack, hence free allocations.</p>
<p>Nevertheless, it is surprising to see that allocations in Java are even faster than malloc. Surprising as it is, calling the new operator in Java requires execution of about 10 instructions whereas a malloc call executes 60 to 100 instructions, hence making Java&#8217;s allocations 6 to 10 times faster! Make sure to check the article titled &#8220;<span>Java theory and practice: </span>Urban performance legends, revisited&#8221; by <a href="http://www.ibm.com/developerworks/java/library/j-jtp09275.html" target="_blank">Brian Goetz</a> if you are interested in details.</p>
<p>Finally, I&#8217;d like to share a few funny quotes this article reminds me about Java:</p>
<ul>
<li>If Java had true garbage collection, most programs would delete themselves upon execution. <em>Robert Sewell</em></li>
<li>Java: the elegant simplicity of C++ and the blazing speed of Smalltalk.</li>
<li>Java is high performance. By high performance we mean adequate. By adequate we mean slow. <em>Mr. Bunny</em></li>
<li>Java is, in many ways, <code>C++--</code>.<em> Michael Feldman<br />
</em></li>
</ul>
<p>Take care <img src='http://www.cetinkoca.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.cetinkoca.com/blog/index.php/2009/03/java-is-so-slow/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Türkçe blog&#8230;</title>
		<link>http://www.cetinkoca.com/blog/index.php/2009/03/turkce-blog/</link>
		<comments>http://www.cetinkoca.com/blog/index.php/2009/03/turkce-blog/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 14:35:37 +0000</pubDate>
		<dc:creator>çetin</dc:creator>
		
		<category><![CDATA[Turkish]]></category>

		<guid isPermaLink="false">http://www.cetinkoca.com/blog/?p=15</guid>
		<description><![CDATA[Merhaba,
Uzun zamandır aklımda olan blog fikrini hayata geçirdim sonunda. Zor kısmı başlamak gibi geliyordu hep, sürekli ertelediğim için olsa gerek. Bu blogda hemen her konuda yazı yayınlamayı düşünüyorum, ilginç, yararlı veya komik olabileceğini düşündüğüm herşeyi.
Temel olarak bazı teknik makaleler ve dersler yayınlayabileceğimi düşünüyorum ve bu yüzden yazıların çoğu İngilizce olacak. Bu yazıları yayınlamamdaki temel amaç [...]]]></description>
			<content:encoded><![CDATA[<p>Merhaba,</p>
<p>Uzun zamandır aklımda olan blog fikrini hayata geçirdim sonunda. Zor kısmı başlamak gibi geliyordu hep, sürekli ertelediğim için olsa gerek. <span id="more-15"></span>Bu blogda hemen her konuda yazı yayınlamayı düşünüyorum, ilginç, yararlı veya komik olabileceğini düşündüğüm herşeyi.</p>
<p>Temel olarak bazı teknik makaleler ve dersler yayınlayabileceğimi düşünüyorum ve bu yüzden yazıların çoğu İngilizce olacak. Bu yazıları yayınlamamdaki temel amaç programlama ile uğraşanlara yardımcı olmak ve aldığım eleştiriler ve tavsiyeler sonucunda kendimi geliştirebilmek. Daha geniş bir kitleye hitap edebilmek için blogu (büyük çoğunlukla) İngilizce olarak hazırlamaya karar verdim. Bu konuda bazı eleştiriler alacağımı tahmin ettiğim için şimdiden bu açıklamayı yapma gereği duydum.</p>
<p>Şimdilik bu kadar.</p>
<p>Görüşmek üzere</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cetinkoca.com/blog/index.php/2009/03/turkce-blog/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Blog is up!</title>
		<link>http://www.cetinkoca.com/blog/index.php/2009/03/the-blog-is-up/</link>
		<comments>http://www.cetinkoca.com/blog/index.php/2009/03/the-blog-is-up/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 12:17:09 +0000</pubDate>
		<dc:creator>çetin</dc:creator>
		
		<category><![CDATA[Miscellaneous]]></category>

		<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://blog.cetinkoca.com/blog/?p=11</guid>
		<description><![CDATA[I didn&#8217;t have time to create a neat website for the stuff I wanted to post, so I thought a blog instead would do the job. I hope to be able to keep this blog updated, once in a while at least. Most of the stuff, especially technical articles and tutorials will be in English [...]]]></description>
			<content:encoded><![CDATA[<p>I didn&#8217;t have time to create a neat website for the stuff I wanted to post, so I thought a blog instead would do the job. <span id="more-11"></span>I hope to be able to keep this blog updated, once in a while at least. Most of the stuff, especially technical articles and tutorials will be in English but I&#8217;ll be posting stuff in Turkish on occasion. I created a different category for Turkish posts to provide convenience for readers. That&#8217;s about it for now.</p>
<p>Have fun</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cetinkoca.com/blog/index.php/2009/03/the-blog-is-up/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
