<?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:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Hnguyen2k's Weblog</title>
	<atom:link href="http://hnguyen2k.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hnguyen2k.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<pubDate>Wed, 30 Jul 2008 23:06:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
			<item>
		<title>C++: Deciphering Pointer Declarations</title>
		<link>http://hnguyen2k.wordpress.com/2008/07/30/c-deciphering-pointer-declarations/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/07/30/c-deciphering-pointer-declarations/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 17:04:36 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Concepts]]></category>

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=27</guid>
		<description><![CDATA[The right-left rule is a simple rule that allows you to interpret any declaration. It runs as follows:
Start reading the declaration from the innermost parentheses, go right, and then go left. When you encounter parentheses, the direction should be reversed. Once everything in the parentheses has been parsed, jump out of it. Continue till the [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The <em>right-left rule</em> is a simple rule that allows you to interpret any declaration. It runs as follows:</p>
<p>Start reading the declaration from the innermost parentheses, go right, and then go left. When you encounter parentheses, the direction should be reversed. Once everything in the parentheses has been parsed, jump out of it. Continue till the whole declaration has been parsed.</p>
<p>One small change to the right-left rule: When you start reading the declaration for the first time, you have to start from the identifier, and not the innermost parentheses.</p>
<p>Take the example given in the introduction:</p>
<pre><span class="code-keyword">int</span> * (* (*fp1) (<span class="code-keyword">int</span>) ) [<span class="code-digit">10</span>];</pre>
<p>This can be interpreted as follows:</p>
<ol>
<li>Start from the variable name &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; <code>fp1</code></li>
<li>Nothing to right but <code>)</code> so go left to find <code>*</code> &#8212;&#8212;&#8212;&#8212;&#8211; is a pointer</li>
<li>Jump out of parentheses and encounter (<code><span class="code-keyword">int</span></code>) &#8212;&#8212;&#8212; to a function that takes an <code><span class="code-keyword">int</span></code> as argument</li>
<li>Go left, find <code>*</code> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- and returns a pointer</li>
<li>Jump put of parentheses, go right and hit <code>[<span class="code-digit">10</span>]</code> &#8212;&#8212;&#8211; to an array of 10</li>
<li>Go left find <code>*</code> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; pointers to</li>
<li>Go left again, find <code><span class="code-keyword">int</span></code> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; <code><span class="code-keyword">int</span></code>s.</li>
</ol>
<p>Here&#8217;s another example:</p>
<pre><span class="code-keyword">int</span> *( *( *arr[<span class="code-digit">5</span>])())();</pre>
<ol>
<li>Start from the variable name &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; <code>arr</code></li>
<li>Go right, find array subscript &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; is an array of 5</li>
<li>Go left, find <code>*</code> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; pointers</li>
<li>Jump out of parentheses, go right to find <code>()</code> &#8212;&#8212; to functions</li>
<li>Go left, encounter <code>*</code> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; that return pointers</li>
<li>Jump out, go right, find <code>()</code> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; to functions</li>
<li>Go left, find <code>*</code> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; that return pointers</li>
<li>Continue left, find <code>*</code> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; to <code><span class="code-keyword">int</span></code>s.</li>
</ol>
<p>Continued reading at: <a href="http://www.codeproject.com/KB/cpp/complex_declarations.aspx#right_left_rule">http://www.codeproject.com/KB/cpp/complex_declarations.aspx#right_left_rule</a><br />
More: <a href="http://www.codeproject.com/KB/cpp/PointerArticle.aspx#11">http://www.codeproject.com/KB/cpp/PointerArticle.aspx#11</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=27&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/07/30/c-deciphering-pointer-declarations/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Network Archtectural Model</title>
		<link>http://hnguyen2k.wordpress.com/2008/07/25/network-archtectural-model/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/07/25/network-archtectural-model/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 19:16:19 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Concepts]]></category>

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=21</guid>
		<description><![CDATA[The TCP/IP model is basically a shorter version of the OSI model. It consists of four instead of seven layers. Despite their architectural differences, both models have interchangeable transport and network layers and their operation is based upon packet-switched technology. The diagram below indicates the differences between the two models:
 


 

Application Layer: The Application layer deals [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The TCP/IP model is basically a shorter version of the OSI model. It consists of four instead of seven layers. Despite their architectural differences, both models have interchangeable transport and network layers and their operation is based upon packet-switched technology. The diagram below indicates the differences between the two models:</p>
<p> </p>
<p><strong><img src="http://www.trainsignaltraining.com/wpnew/wp-content/uploads/2007/10/TCP__OSI___Stelios/1_TCPIP_and_OSI_models.jpg" border="0" alt="TCP/IP and OSI Models" width="412" height="561" align="middle" /></strong><br />
<a id="more-338"></a></p>
<p> </p>
<ul>
<li><strong>Application Layer</strong>: The Application layer deals with representation, encoding and dialog control issues. All these issues are combined together and form a single layer in the TCP/IP model whereas three distinctive layers are defined in the OSI model. </li>
<li><strong>Host-to-Host</strong>: Host-to-Host protocol in the TCP/IP model provides more or less the same services with its equivalent Transport protocol in the OSI model. Its responsibilities include application data segmentation, transmission reliability, flow and error control. </li>
<li><strong>Internet</strong>: Again Internet layer in TCP/IP model provides the same services as the OSIs Network layer. Their purpose is to route packets to their destination independent of the path taken. </li>
<li><strong>Network Access</strong>: The network access layer deals with all the physical issues concerning data termination on network media. It includes all the concepts of the data link and physical layers of the OSI model for both LAN and WAN media.</li>
</ul>
<p><strong>For OSI Model:</strong></p>
<h4>Application Layer</h4>
<ul>
<li>Serves as a window for applications to access network services.</li>
<li>Handles general network access, flow control and error recovery.</li>
</ul>
<h4>Presentation Layer</h4>
<ul>
<li>Determines the format used to exchange data among the networked computers.</li>
<li>Translates data from a format from the Application layer into an intermediate format.</li>
<li>Responsible for protocol conversion, data translation, data encryption, data compression, character conversion, and graphics expansion.</li>
<li>Redirector operates at this level.</li>
</ul>
<h4>Session Layer</h4>
<ul>
<li>Allows two applications running on different computers to establish use and end a connection called a Session.</li>
<li>Performs name recognition and security.</li>
<li>Provides synchronization by placing checkpoints in the data stream.</li>
<li>Implements dialog control between communicating processes.</li>
</ul>
<h4>Transport Layer</h4>
<ul>
<li>Responsible for packet creation.</li>
<li>Provides an additional connection level beneath the Session layer.</li>
<li>Ensures that packets are delivered error free, in sequence with no losses or duplications.</li>
<li>Unpacks, reassembles and sends receipt of messages at the receiving end.</li>
<li>Provides flow control, error handling, and solves transmission problems.</li>
</ul>
<h4>Network Layer</h4>
<ul>
<li>Responsible for addressing messages and translating logical addresses and names into physical addresses.</li>
<li>Determines the route from the source to the destination computer.</li>
<li>Manages traffic such as packet switching, routing and controlling the congestion of data.</li>
</ul>
<h4>Data Link Layer</h4>
<ul>
<li>Sends data frames from the Network layer to the Physical layer.</li>
<li>Packages raw bits into frames for the Network layer at the receiving end.</li>
<li>Responsible for providing error free transmission of frames through the Physical layer.</li>
</ul>
<h4>Physical Layer</h4>
<ul>
<li>Transmits the unstructured raw bit stream over a physical medium.</li>
<li>Relates the electrical, optical mechanical and functional interfaces to the cable.</li>
<li>Defines how the cable is attached to the network adapter card.</li>
<li>Defines data encoding and bit synchronization.</li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=21&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/07/25/network-archtectural-model/feed/</wfw:commentRss>
	
		<media:content url="http://www.trainsignaltraining.com/wpnew/wp-content/uploads/2007/10/TCP__OSI___Stelios/1_TCPIP_and_OSI_models.jpg" medium="image">
			<media:title type="html">TCP/IP and OSI Models</media:title>
		</media:content>
	</item>
		<item>
		<title>Nagle&#8217;s algorithm</title>
		<link>http://hnguyen2k.wordpress.com/2008/07/24/nagles-algorithm/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/07/24/nagles-algorithm/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 22:57:23 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Concepts]]></category>

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=19</guid>
		<description><![CDATA[Nagle&#8217;s algorithm, named after John Nagle, is a means of improving the efficiency of TCP/IP networks by reducing the number of packets that need to be sent over the network.
Nagle&#8217;s document, Congestion Control in IP/TCP Internetworks (RFC896) describes what he called the &#8217;small packet problem&#8217;, where an application repeatedly emits data in small chunks, frequently [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Nagle&#8217;s algorithm</strong>, named after John Nagle, is a means of improving the efficiency of <a class="mw-redirect" title="TCP/IP" href="http://hnguyen2k.wordpress.com/wiki/TCP/IP">TCP/IP</a> networks by reducing the number of packets that need to be sent over the network.</p>
<p>Nagle&#8217;s document, <em>Congestion Control in IP/TCP Internetworks</em> (<a class="external text" title="http://rfc.net/rfc896.html" rel="nofollow" href="http://rfc.net/rfc896.html">RFC896</a>) describes what he called the &#8217;small packet problem&#8217;, where an application repeatedly emits data in small chunks, frequently only 1 <a title="Byte" href="http://hnguyen2k.wordpress.com/wiki/Byte">byte</a> in size. Since <a title="Transmission Control Protocol" href="http://hnguyen2k.wordpress.com/wiki/Transmission_Control_Protocol">TCP</a> packets have a 40 byte header (20 bytes for TCP, 20 bytes for <a title="IPv4" href="http://hnguyen2k.wordpress.com/wiki/IPv4">IPv4</a>), this results in a 41 byte packet for 1 byte of useful information, a huge overhead. This situation often occurs in <a class="mw-redirect" title="Telnet" href="http://hnguyen2k.wordpress.com/wiki/Telnet">Telnet</a> sessions, where most keypresses generate a single byte of data which is transmitted immediately. Worse, over slow links, many such packets can be in transit at the same time, potentially leading to <a class="mw-redirect" title="Congestion collapse" href="http://hnguyen2k.wordpress.com/wiki/Congestion_collapse">congestion collapse</a>.</p>
<p>Nagle&#8217;s algorithm works by <a class="extiw" title="coalesce" href="http://en.wiktionary.org/wiki/coalesce">coalescing</a> a number of small outgoing messages, and sending them all at once. Specifically, as long as there is a sent packet for which the sender has received no acknowledgment, the sender should keep buffering its output until it has a full packet&#8217;s worth of output, so that output can be sent all at once.</p>
<p><a id="Algorithm" name="Algorithm"></a></p>
<h3><span class="mw-headline">Algorithm</span></h3>
<pre><strong>if</strong> there is new data to send
  <strong>if</strong> the window size &gt;= MSS and available data is &gt;= MSS
    send complete MSS segment now
  <strong>else</strong>
    <strong>if</strong> there is unconfirmed data still in the pipe
      enqueue data in the buffer until an acknowledge is received
    <strong>else</strong>
      send data immediately
    <strong>end if</strong>
  <strong>end if</strong>
<strong>end if</strong></pre>
<p>where <em>MSS = <a title="Maximum segment size" href="http://hnguyen2k.wordpress.com/wiki/Maximum_segment_size">Maximum segment size</a></em>.</p>
<p>This algorithm interacts badly with <a class="new" title="TCP delayed acknowledgment (page does not exist)" href="http://hnguyen2k.wordpress.com/w/index.php?title=TCP_delayed_acknowledgment&amp;action=edit&amp;redlink=1">TCP delayed acknowledgments</a>, a feature introduced into TCP at roughly the same time in the early 1980s, but by a different group. With both algorithms enabled, applications which do two successive writes to a TCP connection, followed by a read, experience a constant delay of up to 500 milliseconds, the &#8220;<a class="mw-redirect" title="ACK (TCP)" href="http://hnguyen2k.wordpress.com/wiki/ACK_%28TCP%29">ACK</a> delay&#8221;. For this reason, TCP implementations usually provide applications with an interface to disable the Nagle algorithm. This is typically called the TCP_NODELAY option. The first major application to run into this problem was the <a title="X Window System" href="http://hnguyen2k.wordpress.com/wiki/X_Window_System">X Window System</a>.</p>
<p>The tinygram problem and <a title="Silly window syndrome" href="http://hnguyen2k.wordpress.com/wiki/Silly_window_syndrome">silly window syndrome</a> are sometimes confused. The tinygram problem occurs when the window is almost empty. Silly window syndrome occurs when the window is almost full.</p>
<p>(From Wikipedia)</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=19&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/07/24/nagles-algorithm/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Endianness</title>
		<link>http://hnguyen2k.wordpress.com/2008/07/12/endianness/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/07/12/endianness/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 06:00:06 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Algorithms]]></category>

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=13</guid>
		<description><![CDATA[Big-Endian: MSB has the lowest address (Motoroal processors, SPARC)
Little-endian: LSB has the lowest address (x86, VAX, Z80, 6502)

+ Networks generally use big-endian order
+ English language uses big-endian order
Algorithms to determine the endianness of a machine:
//Return 0 if little-endian; 1 if big-endian
int Endianess1()
{
     int testNum = 1;
     char *ptr = (char*)&#38;testNum;
return *ptr; //return the first byte
}
int Endianness2()
{
      [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p style="text-align:left;"><strong>Big-Endian</strong>: MSB has the lowest address (Motoroal processors, SPARC)<span><a class="image" title="Big-Endian.svg" href="http://hnguyen2k.wordpress.com/wiki/Image:Big-Endian.svg"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/5/54/Big-Endian.svg/280px-Big-Endian.svg.png" border="0" alt="" width="280" height="250" /></a></span></p>
<p><span><strong>Little-endian</strong>: LSB has the lowest address (x86, VAX, Z80, 6502)<br />
<span><a class="image" title="Little-Endian.svg" href="http://hnguyen2k.wordpress.com/wiki/Image:Little-Endian.svg"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Little-Endian.svg/280px-Little-Endian.svg.png" border="0" alt="" width="280" height="250" /></a></span></span></p>
<p>+ Networks generally use big-endian order<br />
+ English language uses big-endian order</p>
<p>Algorithms to determine the endianness of a machine:</p>
<p>//Return 0 if little-endian; 1 if big-endian<br />
int Endianess1()<br />
{<br />
     int testNum = 1;<br />
     char *ptr = (char*)&amp;testNum;</p>
<p>return *ptr; //return the first byte<br />
}</p>
<p>int Endianness2()<br />
{<br />
      union {<br />
           int theInterger;<br />
           char singleByte;<br />
       } endianTest;</p>
<p>       endianTest.theInteger = 1;<br />
       return endianTest.singleByte;<br />
}</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=13&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/07/12/endianness/feed/</wfw:commentRss>
	
		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/5/54/Big-Endian.svg/280px-Big-Endian.svg.png" medium="image" />

		<media:content url="http://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Little-Endian.svg/280px-Little-Endian.svg.png" medium="image" />
	</item>
		<item>
		<title>C++&#8217;s Memory Areas</title>
		<link>http://hnguyen2k.wordpress.com/2008/06/30/cs-memory-areas/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/06/30/cs-memory-areas/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 23:16:33 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Concepts]]></category>

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=12</guid>
		<description><![CDATA[The following table summarizes a C++ program&#8217;s major distinct memory areas. Note that some of the names (for example, &#8220;heap&#8221;) do not appear as such in the standard; in particular, &#8220;heap&#8221; and &#8220;free store&#8221; are common and convenient shorthands for distinguishing between two kinds of dynamically allocated memory.



Table 1. C++&#8217;s Memory Areas




Memory Area
Characteristics and Object [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="docText">The following table summarizes a C++ program&#8217;s major distinct memory areas. Note that some of the names (for example, &#8220;heap&#8221;) do not appear as such in the standard; in particular, &#8220;heap&#8221; and &#8220;free store&#8221; are common and convenient shorthands for distinguishing between two kinds of dynamically allocated memory.</p>
<p><a name="ch35table01"></a></p>
<table class="allBorders" border="1" cellspacing="0" width="100%">
<caption>
<h5 class="docTableTitle">Table 1. C++&#8217;s Memory Areas</h5>
</caption>
<p><col span="1"></col><col span="1"></col></p>
<thead>
<tr>
<th class="docTableCell thead" align="left" valign="middle" scope="col"><span class="docEmphStrong">Memory Area</span></th>
<th class="docTableCell thead" align="left" valign="middle" scope="col"><span class="docEmphStrong">Characteristics and Object Lifetimes</span></th>
</tr>
</thead>
<tbody>
<tr>
<td class="docTableCell" align="left" valign="top">Const Data</td>
<td class="docTableCell" align="left" valign="top">The const data area stores string literals and other data whose values are known at compile-time. No objects of class type can exist in this area. All data in this area is available during the entire lifetime of the program. Further, all this data is read-only, and the results of trying to modify it are undefined. This is in part because even the underlying storage format is subject to arbitrary optimization by the implementation. For example, a particular compiler may choose to store string literals in overlapping objects as an optional optimization.</td>
</tr>
<tr>
<td class="docTableCell" align="left" valign="top">Stack</td>
<td class="docTableCell" align="left" valign="top">The stack stores automatic variables. Objects are constructed immediately at the point of definition and destroyed immediately at the end of the same scope, so there is no opportunity for programmers to directly manipulate allocated but uninitialized stack space (barring willful tampering using explicit destructors and placement <tt>new</tt>). Stack memory allocation is typically much faster than for dynamic storage (heap or free store) because each stack memory allocation involves only a stack pointer increment rather than more-complex management.</td>
</tr>
<tr>
<td class="docTableCell" align="left" valign="top">Free Store</td>
<td class="docTableCell" align="left" valign="top">The free store is one of the two dynamic memory areas allocated/freed by <tt>new</tt>/<tt>delete</tt>. Object lifetime can be less than the time the storage is allocated. That is, free store objects can have memory allocated, without being immediately initialized, and they can be destroyed, without the memory being immediately deallocated. During the period when the storage is allocated but outside the object&#8217;s lifetime, the storage may be accessed and manipulated through a <tt>void*</tt>, but none of the proto-object&#8217;s nonstatic members or member functions may be accessed, have their addresses taken, or be otherwise manipulated.</td>
</tr>
<tr>
<td class="docTableCell" align="left" valign="top">Heap</td>
<td class="docTableCell" align="left" valign="top">The heap is the other dynamic memory area allocated/freed by <tt>malloc()</tt>/<tt>free()</tt> and their variants.</p>
<p class="docText">Note that while the default global operators <tt>new</tt> and <tt>delete</tt> might be implemented in terms of <tt>malloc()</tt> and <tt>free()</tt> by a particular compiler, the heap is not the same as free store, and memory allocated in one area cannot be safely deallocated in the other.</p>
<p>Memory allocated from the heap can be used for objects of class type by placement <tt>new</tt> construction and explicit destruction. If so used, the notes about free store object lifetime apply similarly here.</td>
</tr>
<tr>
<td class="docTableCell" align="left" valign="top">Global/Static</td>
<td class="docTableCell bottomBorder" align="left" valign="top">Global or static variables and objects have their storage allocated at program startup, but may not be initialized until after the program has begun executing. For instance, a static variable in a function is initialized only the first time program execution passes through its definition. The order of initialization of global variables across translation units is not defined, and special care is needed to manage dependencies between global objects (including class statics). As always, uninitialized proto-objects&#8217; storage may be accessed and manipulated through a <tt>void*</tt>, but no nonstatic members or member functions may be used or referenced outside the object&#8217;s actual lifetime.</td>
</tr>
</tbody>
</table>
<p> </p>
<p class="docText">It&#8217;s important to distinguish between the &#8220;heap&#8221; and the &#8220;free store,&#8221; because the standard deliberately leaves unspecified the question of whether these two areas are related. For example, when memory is deallocated via <tt>::operator delete()</tt>, the final note in section 18.4.1.1 of the C++ standard states:</p>
<blockquote>
<p class="docText"><span class="docEmphasis">&#8220;It is unspecified under what conditions part or all of such reclaimed storage is allocated by a subsequent call to <tt>operator new</tt> or any of <tt>calloc</tt>, <tt>malloc</tt>, or <tt>realloc</tt>, declared in <tt>&lt;cstdlib&gt;</tt>.&#8221;</span></p>
</blockquote>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/12/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/12/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=12&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/06/30/cs-memory-areas/feed/</wfw:commentRss>
		</item>
		<item>
		<title>UTF–8 and Extended characters</title>
		<link>http://hnguyen2k.wordpress.com/2008/06/12/utf%e2%80%938-and-extended-characters/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/06/12/utf%e2%80%938-and-extended-characters/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 19:01:06 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Concepts]]></category>

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=11</guid>
		<description><![CDATA[



Character Range (hex)


 
Unicode (UCS-2/UTF-16)


UTF-8




0-7F


00000000 0xxxxxxx


0xxxxxxx




80-7FF


00000xxx xxxxxxxx


110xxxxx 10xxxxxx




800-FFFF


xxxxxxxx xxxxxxxx


1110xxxx 10xxxxxx 10xxxxxx




10000-1FFFFF


- out of range - 


11110xxx 10xxxxxx 10xxxxxx
10xxxxxx



200000-3FFFFFF


- out of range - 


111110xx 10xxxxxx 10xxxxxx
10xxxxxx 10xxxxxx



4000000-7FFFFFFF


- out of range - 


1111110x 10xxxxxx 10xxxxxx
10xxxxxx 10xxxxxx 10xxxxxx



Note that all bytes of multi-byte UTF-8 characters have the high-bit set to one, and only the first byte of a multi-byte [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><table class="MsoNormalTable" style="width:100%;" border="1" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td style="background:#eeeeee;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="text-align:center;margin:0;" align="center"><span style="font-size:9pt;font-family:Arial;">Character</span><span style="font-size:9pt;font-family:Arial;"> Range</span><span style="font-size:9pt;font-family:Arial;"> (hex)</span></p>
</td>
<td style="background:#eeeeee;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="text-align:center;margin:0;" align="center"><span style="font-size:9pt;font-family:Arial;"> </span></p>
<p class="MsoNormal" style="text-align:center;margin:0;" align="center"><span style="font-size:9pt;font-family:Arial;">Unicode (UCS-2/UTF-16)</span></p>
</td>
<td style="background:#eeeeee;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="text-align:center;margin:0;" align="center"><span style="font-size:9pt;font-family:Arial;">UTF-8</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">0-7F</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">00000000 0xxxxxxx</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">0xxxxxxx</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">80-7FF</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">00000xxx xxxxxxxx</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">110xxxxx 10xxxxxx</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">800-FFFF</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">xxxxxxxx xxxxxxxx</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">1110xxxx 10xxxxxx 10xxxxxx</span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">10000-1FFFFF</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><em><span style="font-size:9pt;font-family:&quot;">- out of range -</span></em><span style="font-size:9pt;font-family:&quot;"> </span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">11110xxx 10xxxxxx 10xxxxxx<br />
10xxxxxx</span></td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">200000-3FFFFFF</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><em><span style="font-size:9pt;font-family:&quot;">- out of range -</span></em><span style="font-size:9pt;font-family:&quot;"> </span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">111110xx 10xxxxxx 10xxxxxx<br />
10xxxxxx 10xxxxxx</span></td>
</tr>
<tr>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">4000000-7FFFFFFF</span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><em><span style="font-size:9pt;font-family:&quot;">- out of range -</span></em><span style="font-size:9pt;font-family:&quot;"> </span></p>
</td>
<td style="background-color:transparent;border:#d4d0c8;padding:3pt;">
<p class="MsoNormal" style="margin:0;"><span style="font-size:9pt;font-family:&quot;">1111110x 10xxxxxx 10xxxxxx<br />
10xxxxxx 10xxxxxx 10xxxxxx</span></td>
</tr>
</tbody>
</table>
<p><span style="font-size:small;font-family:Times New Roman;">Note that all bytes of multi-byte UTF-8 characters have the high-bit set to one, and only the first byte of a multi-byte character has both its highest bits set. This means there can never be confusion about where a character starts. So in UTF-8, the combined Greek and Latin sequence <strong>aβcδe</strong> is represented by the following seven bytes, and looking at the high bits you can pick out the extended characters without too much trouble:</span></p>
<p style="text-align:center;" align="center"><span style="font-size:9.5pt;font-family:&quot;">01100001 <span style="text-decoration:underline;">11001110 10110010</span> 01100011 <span style="text-decoration:underline;">11001110 10110100</span> 01100101</span></p>
<p><span style="font-size:small;font-family:Times New Roman;">Now the <em>really</em> clever bit about UTF-8 is that it is capable of passing unharmed through ASCII only systems [programs which don’t even recognize UTF-8], thanks to the fact that each character beyond U+007F looks like a valid sequence of extended ASCII when read as a byte-per-character. This is in stark contrast to other Unicode encodings such as UCS-2, which are full of zero bytes and therefore wreak havoc with ASCII processing systems. To an ASCII system, the UTF-8 representation of <strong>aβcδe</strong> parses as <strong>aÎ²cÎ´e</strong> . On the surface this may seem like a corruption, but the important thing to note is that <em>no illegal ASCII characters appear in a UTF-8 bytestream</em>, and so the same string can be read and written out again as raw ASCII and then decoded later as the original UTF-8. With the exception of 7-bit text systems [a legacy email standard, unfortunately, for which the hideous UTF-7 had to be invented] UTF-8 should be able to pass through ASCII systems unscathed.</span></p>
<p> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=11&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/06/12/utf%e2%80%938-and-extended-characters/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Exception safety</title>
		<link>http://hnguyen2k.wordpress.com/2008/06/09/exception-safety/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/06/09/exception-safety/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 17:32:28 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Concepts]]></category>

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=10</guid>
		<description><![CDATA[Never allow an exception to escape from a destructor or from an overloaded operator delete() or operator delete[](); write every destructor and deallocation as though it had an exception specification of &#8220;throw()&#8221;
In each function, take all the code that might emit an exception and do all the work safely off to the side. Only then, [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Never allow an exception to escape from a destructor or from an overloaded <em>operator delete()</em> or <em>operator delete[](); </em>write every destructor and deallocation as though it had an exception specification of &#8220;throw()&#8221;</p>
<p>In each function, take all the code that might emit an exception and do all the work safely off to the side. Only then, when you know that the real work has succeeded, should you modifiy the program state (and clean up) using only non-throwing operations.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/10/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/10/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/10/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/10/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/10/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=10&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/06/09/exception-safety/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Pleasure of Reading</title>
		<link>http://hnguyen2k.wordpress.com/2008/05/19/the-pleasure-of-reading/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/05/19/the-pleasure-of-reading/#comments</comments>
		<pubDate>Mon, 19 May 2008 08:16:36 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Essays]]></category>

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=9</guid>
		<description><![CDATA[    Animals may have moments of pleasure but only man has got a lot to do with it. It is through our sense of organs that we enjoy pleasure. The sense of smell, sight, hearing, touch and taste each brings pleasure. Even the baby as soon as it is born feels the pleasure of suckling [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>    Animals may have moments of pleasure but only man has got a lot to do with it. It is through our sense of organs that we enjoy pleasure. The sense of smell, sight, hearing, touch and taste each brings pleasure. Even the baby as soon as it is born feels the pleasure of suckling and the comfort of being cuddled in the wads of cloth in the mother&#8217;s lap. But for the pleasing smell we will not be able to enjoy our food. We are thrilled by the sight of ice capped mountains or the roaring water falls of the Niagara. So they are the sense that help us to get the pleasure. </p>
<p>    There is no end to the sources of pleasure. But reading for pleasure belongs to a higher order and stands as a category by itself. While external things bring pleasure to the sense organs, reading brings pleasure to the mind. Greater the mind is cultured, greater will be the pleasure derived from reading for reading makes full man.</p>
<p>    Reading is the end product of writing. Unless there is something written one cannot read. So good writing is a concomitant of reading. Man alone can write, in other words put his ideas in black and white. In fact even before printing came into being man was writing and it is as old as modern civilization. Man can preserve his thoughts and ideas through writing. Thus the whole world of literature is there for one to read.</p>
<p>   Now reading material is available for all tastes. A scholar may go through serious writing for the sake of enriching his knowledge. Another may read a magazine or a picture book for whiling away the time. One chooses the reading material according to his moods, his literary background, the time at his disposal and ther purpose if any. A teenager may like stories of romance and an old man may prefer books on philosophy and religion. Some gifted with imagination and the faculty to reflect may read poetry.</p>
<p>   One who takes pleasure in reading always tries to build his library. Very often a good library may serve the purpose.</p>
<p>   The greatest advantage in reading is when one comes across great minds. Whether you agree with what is there to  read or do not agree there will not be any quarrel. You may pronounce your judgement on the writer. There will be no harm if your judgment is silent and not published.</p>
<p>   Given the proper atmosphere like a good silent place, soft light and comfortable seat, one can read and read and enjoy it.</p>
<p>   There are greate master of writing in all great languages of the world. English language abounds in such great authors. Again it may be poetry, novel, fiction, drama, travelogue, letters and so on. Biographies and autobiographies form a sizable part. In these days of rush good magazines supply the material for reading. For example , one may cite the Reader&#8217;s Digest.</p>
<p>   In order to enjoy reading, one must cultivate that habit. It can be ennobling. There is dignity in the reading habit.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=9&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/05/19/the-pleasure-of-reading/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C++: RAII with auto_ptr and shared_ptr</title>
		<link>http://hnguyen2k.wordpress.com/2008/05/16/c-raii-with-auto_ptr-and-shared_ptr/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/05/16/c-raii-with-auto_ptr-and-shared_ptr/#comments</comments>
		<pubDate>Fri, 16 May 2008 00:41:47 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Concepts]]></category>

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=8</guid>
		<description><![CDATA[RAII: Resource Aquisition Is Initialization - The technique combines acquisition and release of resources with initialization and uninitialization of objects.
auto_ptr: is a pointer-like object (a smart pointer), whose destructor automatically calls delete on what it points to. It&#8217;s important that there never be more than one aut_ptr pointing to an object because an auto_ptr automatically [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>RAII: <em>Resource Aquisition Is Initialization</em> - The technique combines acquisition and release of resources with initialization and uninitialization of objects.</p>
<p><em>auto_ptr: </em>is a pointer-like object (a smart pointer), whose destructor automatically calls delete on what it points to. It&#8217;s important that there never be more than one aut_ptr pointing to an object because an auto_ptr automatically delete what it points to when the auto_ptr is destroyed.<br />
      std::auto_ptr&lt;Student&gt;p1(new Student);    //p1 points to an Student object<br />
      std::auto_ptr&lt;Student&gt;p2(p1);                  //p2 now points to the obj, p1 is now null<br />
      p1 = p2                                                       //p1 now points to the obj, p2 is null</p>
<p><em>shared_ptr</em>: is a reference-counting smart pointer that keeps tracks of how many objects point to a particular resource and automatically deletes the resource when nobody is pointing to it any longer. (Like a garbage collection except that such pointers can&#8217;t break cycles of references, e.i two otherwise unused objects that point to one another)<br />
     std::tr1::shared_ptr&lt;Student&gt;p1(new Student);  //p1 points to a Student object<br />
     std::tr1::shared_ptr&lt;Student&gt;p2(p1);                //both p1 and p2 point to the object<br />
     p1 = p2;                                                            //same</p>
<p>Both auto_ptr and tr1::shared_ptr use delete in their destructors, not delete[]. Therefore, they should not be used with dynamically allocated arrays:<br />
    std::auto_ptr&lt;std::string&gt; aps(new std::string[10]);  //bad<br />
    std::tr1::shared_ptr&lt;int&gt;spi(new int[1024]);             //bad  </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=8&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/05/16/c-raii-with-auto_ptr-and-shared_ptr/feed/</wfw:commentRss>
		</item>
		<item>
		<title>C++ placement new</title>
		<link>http://hnguyen2k.wordpress.com/2008/05/15/c-placement-new/</link>
		<comments>http://hnguyen2k.wordpress.com/2008/05/15/c-placement-new/#comments</comments>
		<pubDate>Thu, 15 May 2008 23:14:22 +0000</pubDate>
		<dc:creator>hnguyen2k</dc:creator>
		
		<category><![CDATA[Concepts]]></category>

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

		<guid isPermaLink="false">http://hnguyen2k.wordpress.com/?p=7</guid>
		<description><![CDATA[Operator new allocates memory from the heap, on which an object is constructed. Standard C++ also supports placement new operator, which constructs an object on a pre-allocated buffer. This is useful when building a memory pool, a garbage collector or simply when performance and exception safety are paramount (there&#8217;s no danger of allocation failure since [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Operator new allocates memory from the heap, on which an object is constructed. Standard C++ also supports placement new operator, which constructs an object on a pre-allocated buffer. This is useful when building a memory pool, a garbage collector or simply when performance and exception safety are paramount (there&#8217;s no danger of allocation failure since the memory has already been allocated, and constructing an object on a pre-allocated buffer takes less time): </p>
<p>   char *buf  = new char[1000];        //pre-allocated buffer<br />
   string *p = new (buf) string(&#8221;hi&#8221;);  //placement new<br />
   string *q = new string(&#8221;hi&#8221;);          //ordinary heap allocation</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/hnguyen2k.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/hnguyen2k.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/hnguyen2k.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/hnguyen2k.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/hnguyen2k.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/hnguyen2k.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/hnguyen2k.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/hnguyen2k.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/hnguyen2k.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/hnguyen2k.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/hnguyen2k.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/hnguyen2k.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=hnguyen2k.wordpress.com&blog=3297943&post=7&subd=hnguyen2k&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://hnguyen2k.wordpress.com/2008/05/15/c-placement-new/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>