<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Programming tips</title>
	<atom:link href="http://www.purinchu.net/wp/2008/06/03/programming-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.purinchu.net/wp/2008/06/03/programming-tips/</link>
	<description>The answer to life, the universe, and everything</description>
	<pubDate>Fri, 05 Dec 2008 04:36:34 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: <img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=77bfae11a6e64f5e8dba6236fbc65bbc&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/85999e16b245759.png" alt="mpyne Identicon Icon" height="35" width="35" /> mpyne</title>
		<link>http://www.purinchu.net/wp/2008/06/03/programming-tips/#comment-5732</link>
		<dc:creator><img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=77bfae11a6e64f5e8dba6236fbc65bbc&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/85999e16b245759.png" alt="mpyne Identicon Icon" height="35" width="35" /> mpyne</dc:creator>
		<pubDate>Thu, 05 Jun 2008 03:54:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.purinchu.net/wp/?p=242#comment-5732</guid>
		<description>BTW, I changed the usage of memcpy() in trunk.  But it turns out that Qt 4 has support for this type of object (has ctor/dtor, but memcpy()able).  If you look at the information for Q_DECLARE_TYPEINFO in Qt 4 then check the Q_MOVABLE_TYPE flag.</description>
		<content:encoded><![CDATA[<p>BTW, I changed the usage of memcpy() in trunk.  But it turns out that Qt 4 has support for this type of object (has ctor/dtor, but memcpy()able).  If you look at the information for Q_DECLARE_TYPEINFO in Qt 4 then check the Q_MOVABLE_TYPE flag.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: <img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=77bfae11a6e64f5e8dba6236fbc65bbc&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/85999e16b245759.png" alt="mpyne Identicon Icon" height="35" width="35" /> mpyne</title>
		<link>http://www.purinchu.net/wp/2008/06/03/programming-tips/#comment-5731</link>
		<dc:creator><img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=77bfae11a6e64f5e8dba6236fbc65bbc&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/85999e16b245759.png" alt="mpyne Identicon Icon" height="35" width="35" /> mpyne</dc:creator>
		<pubDate>Tue, 03 Jun 2008 22:22:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.purinchu.net/wp/?p=242#comment-5731</guid>
		<description>maninalift, moltonel: Yes, the pixmap cache is both compiler and architecture dependent.  That's one of the reasons I imagine the author of the code chose to put it into /var/tmp.

litb:You are right, memcpy() will not work to create a C++ object that is not a POD (plain old data) class.

I was under the impression that merely adding a constructor to a class would not change it's POD-ness, but that's not the case in the current C++ standard.  So thanks for the tip, I'll get that fixed.</description>
		<content:encoded><![CDATA[<p>maninalift, moltonel: Yes, the pixmap cache is both compiler and architecture dependent.  That&#8217;s one of the reasons I imagine the author of the code chose to put it into /var/tmp.</p>
<p>litb:You are right, memcpy() will not work to create a C++ object that is not a POD (plain old data) class.</p>
<p>I was under the impression that merely adding a constructor to a class would not change it&#8217;s POD-ness, but that&#8217;s not the case in the current C++ standard.  So thanks for the tip, I&#8217;ll get that fixed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: <img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=d41d8cd98f00b204e9800998ecf8427e&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/969a61db97440b6.png" alt="litb Identicon Icon" height="35" width="35" /> litb</title>
		<link>http://www.purinchu.net/wp/2008/06/03/programming-tips/#comment-5730</link>
		<dc:creator><img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=d41d8cd98f00b204e9800998ecf8427e&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/969a61db97440b6.png" alt="litb Identicon Icon" height="35" width="35" /> litb</dc:creator>
		<pubDate>Tue, 03 Jun 2008 11:11:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.purinchu.net/wp/?p=242#comment-5730</guid>
		<description>it looks like you plan to memcpy your struct out of the mmapped area into an object of that struct. 
i want to tell you that this will not work reliable (it is in fact undefined behaivor), because the struct defines a user-defined constructor, and is therefor not POD anymore. you are not allowed to use memcpy, memcmp or anything like that anymore then. all in all nice blog, thanks for writing it :)</description>
		<content:encoded><![CDATA[<p>it looks like you plan to memcpy your struct out of the mmapped area into an object of that struct.<br />
i want to tell you that this will not work reliable (it is in fact undefined behaivor), because the struct defines a user-defined constructor, and is therefor not POD anymore. you are not allowed to use memcpy, memcmp or anything like that anymore then. all in all nice blog, thanks for writing it :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: <img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=d20f86db9a6f03cb070e9fbaaf0b7228&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/4b3db754c2b3870.png" alt="moltonel Identicon Icon" height="35" width="35" /> moltonel</title>
		<link>http://www.purinchu.net/wp/2008/06/03/programming-tips/#comment-5724</link>
		<dc:creator><img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=d20f86db9a6f03cb070e9fbaaf0b7228&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/4b3db754c2b3870.png" alt="moltonel Identicon Icon" height="35" width="35" /> moltonel</dc:creator>
		<pubDate>Tue, 03 Jun 2008 10:19:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.purinchu.net/wp/?p=242#comment-5724</guid>
		<description>Nice way to fix the bug, except you're putting your architecture's binary expectations into a file that could be read from different architectures. In a typical school or lab environement, you have your home on NFS (or similar) and log in using any available machine. If I open a session successively on to machines with differing alignment, I get a crash. Correct ?

Solution ?

Simple way is to use a "safe" alignment, like 16 bytes, which will be compatible with smaller alignments (assuming you'll never see wacky alignment requirements, like "6 bytes"). Note that you can tell gcc how you want your structure aligned. Other compilers will have other syntaxes.

Safe way is to read byte by byte, and bitshift in memory.

Cunning way (wild idea, dunno if it'd work) would be to mmap the file with an offset, so that the part that you want to read aligned is indeed aligned. Huh... there's certainly a reason why this wouldn't work, but it's a fun idea :)</description>
		<content:encoded><![CDATA[<p>Nice way to fix the bug, except you&#8217;re putting your architecture&#8217;s binary expectations into a file that could be read from different architectures. In a typical school or lab environement, you have your home on NFS (or similar) and log in using any available machine. If I open a session successively on to machines with differing alignment, I get a crash. Correct ?</p>
<p>Solution ?</p>
<p>Simple way is to use a &#8220;safe&#8221; alignment, like 16 bytes, which will be compatible with smaller alignments (assuming you&#8217;ll never see wacky alignment requirements, like &#8220;6 bytes&#8221;). Note that you can tell gcc how you want your structure aligned. Other compilers will have other syntaxes.</p>
<p>Safe way is to read byte by byte, and bitshift in memory.</p>
<p>Cunning way (wild idea, dunno if it&#8217;d work) would be to mmap the file with an offset, so that the part that you want to read aligned is indeed aligned. Huh&#8230; there&#8217;s certainly a reason why this wouldn&#8217;t work, but it&#8217;s a fun idea :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: <img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=dce5c32bdd896bdf91f27c9766624cc7&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/ea04596ed0d1586.png" alt="maninalift Identicon Icon" height="35" width="35" /> maninalift</title>
		<link>http://www.purinchu.net/wp/2008/06/03/programming-tips/#comment-5719</link>
		<dc:creator><img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=dce5c32bdd896bdf91f27c9766624cc7&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/ea04596ed0d1586.png" alt="maninalift Identicon Icon" height="35" width="35" /> maninalift</dc:creator>
		<pubDate>Tue, 03 Jun 2008 08:51:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.purinchu.net/wp/?p=242#comment-5719</guid>
		<description>KPixmapCacheDataHeader is a nice trick but I feel that it could be bade nicer. Hmmm.

I am probably just confused but it seems that a problem with this approach is that your file format is platform- and, theoretically at least, compiler-dependent.</description>
		<content:encoded><![CDATA[<p>KPixmapCacheDataHeader is a nice trick but I feel that it could be bade nicer. Hmmm.</p>
<p>I am probably just confused but it seems that a problem with this approach is that your file format is platform- and, theoretically at least, compiler-dependent.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: <img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=d41d8cd98f00b204e9800998ecf8427e&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/969a61db97440b6.png" alt="Jason Identicon Icon" height="35" width="35" /> Jason</title>
		<link>http://www.purinchu.net/wp/2008/06/03/programming-tips/#comment-5714</link>
		<dc:creator><img class="identicon" src="http://www.gravatar.com/avatar.php?gravatar_id=d41d8cd98f00b204e9800998ecf8427e&#38;size=35&#38;default=http://www.purinchu.net/wp/wp-content/plugins/wp-identicon/identicon/969a61db97440b6.png" alt="Jason Identicon Icon" height="35" width="35" /> Jason</dc:creator>
		<pubDate>Tue, 03 Jun 2008 06:19:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.purinchu.net/wp/?p=242#comment-5714</guid>
		<description>For something simple like the version number, you could also read the integer one byte at a time and bitshift it, especially for cases where you don't have control over the file format and can't guarantee any kind of alignment.</description>
		<content:encoded><![CDATA[<p>For something simple like the version number, you could also read the integer one byte at a time and bitshift it, especially for cases where you don&#8217;t have control over the file format and can&#8217;t guarantee any kind of alignment.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
