<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Crunching bytes</title>
	<atom:link href="http://msinilo.pl/blog/?feed=rss2&#038;p=425" rel="self" type="application/rss+xml" />
	<link>http://msinilo.pl/blog/?p=425</link>
	<description>Random gamedev ramblings</description>
	<lastBuildDate>Sun, 05 Sep 2010 06:59:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<item>
		<title>By: Be nice to your cache &#124; .mischief.mayhem.soap.</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-20592</link>
		<dc:creator>Be nice to your cache &#124; .mischief.mayhem.soap.</dc:creator>
		<pubDate>Sun, 25 Apr 2010 15:36:23 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-20592</guid>
		<description>[...] not bloat your structures. Think about padding (Cruncher# to the rescue!), use bitfields instead of multiple bools, consider using smaller data types. Of [...]</description>
		<content:encoded><![CDATA[<p>[...] not bloat your structures. Think about padding (Cruncher# to the rescue!), use bitfields instead of multiple bools, consider using smaller data types. Of [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-20192</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 29 Mar 2010 20:21:34 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-20192</guid>
		<description>@Jumpster: that&#039;s exactly right (= layout conclusions). With classes is exactly the same (the only difference in C++ is that class members are private by default, generated code is identical). 
About the optimal structure suggestion -- it&#039;s probably a good idea, but problem is not trivial (variation of knapsack, basically), so it&#039;s something I postponed until I have more free time.</description>
		<content:encoded><![CDATA[<p>@Jumpster: that&#8217;s exactly right (= layout conclusions). With classes is exactly the same (the only difference in C++ is that class members are private by default, generated code is identical).<br />
About the optimal structure suggestion &#8212; it&#8217;s probably a good idea, but problem is not trivial (variation of knapsack, basically), so it&#8217;s something I postponed until I have more free time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jumpster</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-20036</link>
		<dc:creator>Jumpster</dc:creator>
		<pubDate>Sat, 20 Mar 2010 00:11:12 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-20036</guid>
		<description>Perhaps a future revision to Cruncher# may offer a *suggestion* of a new structure format that minimizes the padding requirements?

Just a suggestion, pretty cool program! 

Me likey,
Jumpster</description>
		<content:encoded><![CDATA[<p>Perhaps a future revision to Cruncher# may offer a *suggestion* of a new structure format that minimizes the padding requirements?</p>
<p>Just a suggestion, pretty cool program! </p>
<p>Me likey,<br />
Jumpster</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jumpster</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-20034</link>
		<dc:creator>Jumpster</dc:creator>
		<pubDate>Fri, 19 Mar 2010 23:55:04 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-20034</guid>
		<description>It took me a bit to envision what you are saying, but I get it now: Using your example;


  struct one {
    byte byte_1;  // 3-bytes padding
    int  int_1;
    byte byte_2;
    byte byte_3;
    byte byte_4;  // 1-byte padding
  }; // sizeof() = 12

  struct two {
    byte byte_1;
    byte byte_2;
    byte byte_3;
    byte byte_4;
    int  int_1;   // No padding
  }; // sizeof() = 8 -&gt; 33% savings...

I&#039;m glad I stumbled upon your site. In all my years of programming, I never realized the inefficiencies caused by my data structures.

Just a question tho, although I could check this myself - but if you already know the answer... :)

Anyway, since classes and structs are essentially the same, then is it safe to assume class structures have the same types of inefficiencies?  

I tend to place class definitions (methods/member vars/etc) in what I feel is a logical point, I assume that classes should be looked at too?

Anyway, thanks for the info. That was something I didn&#039;t know.

Regards,
Jumpster</description>
		<content:encoded><![CDATA[<p>It took me a bit to envision what you are saying, but I get it now: Using your example;</p>
<p>  struct one {<br />
    byte byte_1;  // 3-bytes padding<br />
    int  int_1;<br />
    byte byte_2;<br />
    byte byte_3;<br />
    byte byte_4;  // 1-byte padding<br />
  }; // sizeof() = 12</p>
<p>  struct two {<br />
    byte byte_1;<br />
    byte byte_2;<br />
    byte byte_3;<br />
    byte byte_4;<br />
    int  int_1;   // No padding<br />
  }; // sizeof() = 8 -&gt; 33% savings&#8230;</p>
<p>I&#8217;m glad I stumbled upon your site. In all my years of programming, I never realized the inefficiencies caused by my data structures.</p>
<p>Just a question tho, although I could check this myself &#8211; but if you already know the answer&#8230; :)</p>
<p>Anyway, since classes and structs are essentially the same, then is it safe to assume class structures have the same types of inefficiencies?  </p>
<p>I tend to place class definitions (methods/member vars/etc) in what I feel is a logical point, I assume that classes should be looked at too?</p>
<p>Anyway, thanks for the info. That was something I didn&#8217;t know.</p>
<p>Regards,<br />
Jumpster</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-19958</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Wed, 17 Mar 2010 08:58:37 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-19958</guid>
		<description>You understand it correctly. That&#039;s why I don&#039;t advocate using #pragma pack(1) (this would force 1-byte alignment and eliminate padding, the &#039;easy&#039; way). Instead we want to minimize &#039;holes&#039; caused by inefficient alignment. For example, if there&#039;s a byte, followed by int, followed by 3 bytes, it&#039;d be more effective to rearrange it so that 4 1-byte member go first, then goes integer. In real world cases it&#039;s usually impossible to eliminate them completely, but I&#039;ve been able to reduce size of important structures by ~10-15% just by shuffling variables around.</description>
		<content:encoded><![CDATA[<p>You understand it correctly. That&#8217;s why I don&#8217;t advocate using #pragma pack(1) (this would force 1-byte alignment and eliminate padding, the &#8216;easy&#8217; way). Instead we want to minimize &#8216;holes&#8217; caused by inefficient alignment. For example, if there&#8217;s a byte, followed by int, followed by 3 bytes, it&#8217;d be more effective to rearrange it so that 4 1-byte member go first, then goes integer. In real world cases it&#8217;s usually impossible to eliminate them completely, but I&#8217;ve been able to reduce size of important structures by ~10-15% just by shuffling variables around.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jumpster</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-19949</link>
		<dc:creator>Jumpster</dc:creator>
		<pubDate>Wed, 17 Mar 2010 02:30:33 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-19949</guid>
		<description>I realize I&#039;m a bit late here, but I&#039;m a bit confused...

I understand the reason for *saving* memory (ie: reduce memory padding to save resources) but I was under the impression that aligning structures to a native size (4-bytes on 32-bit systems / 8-bytes on 64-bit systems) improves efficiency due to the memory/cache access improvements? Am I misunderstanding something here?

Regards,
Jumpster</description>
		<content:encoded><![CDATA[<p>I realize I&#8217;m a bit late here, but I&#8217;m a bit confused&#8230;</p>
<p>I understand the reason for *saving* memory (ie: reduce memory padding to save resources) but I was under the impression that aligning structures to a native size (4-bytes on 32-bit systems / 8-bytes on 64-bit systems) improves efficiency due to the memory/cache access improvements? Am I misunderstanding something here?</p>
<p>Regards,<br />
Jumpster</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Structure Padding Analysis Tools &#124; Rachels Lab Notes</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-17128</link>
		<dc:creator>Structure Padding Analysis Tools &#124; Rachels Lab Notes</dc:creator>
		<pubDate>Thu, 22 Oct 2009 15:19:07 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-17128</guid>
		<description>[...] yet, occasionally, something slips through. So it&#8217;s nice that somebody wrote a tool &#8211; Cruncher# &#8211; to just load your PDB and examine all your structures for unnecessary [...]</description>
		<content:encoded><![CDATA[<p>[...] yet, occasionally, something slips through. So it&#8217;s nice that somebody wrote a tool &#8211; Cruncher# &#8211; to just load your PDB and examine all your structures for unnecessary [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arseny Kapoulkine</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-16236</link>
		<dc:creator>Arseny Kapoulkine</dc:creator>
		<pubDate>Tue, 15 Sep 2009 18:37:14 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-16236</guid>
		<description>Remembered about this once again through Twitter link :) Got a msdia90.dll, registered it - now it works! I wonder if there&#039;s an official way to do it (except installing MSVS 2008...).</description>
		<content:encoded><![CDATA[<p>Remembered about this once again through Twitter link :) Got a msdia90.dll, registered it &#8211; now it works! I wonder if there&#8217;s an official way to do it (except installing MSVS 2008&#8230;).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-16115</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Tue, 08 Sep 2009 21:27:18 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-16115</guid>
		<description>Yes, that&#039;s DIA. If I remember correctly I used msdia90.dll from latest Microsoft&#039;s Debugging SDK. C# tends to act weirdly sometimes...</description>
		<content:encoded><![CDATA[<p>Yes, that&#8217;s DIA. If I remember correctly I used msdia90.dll from latest Microsoft&#8217;s Debugging SDK. C# tends to act weirdly sometimes&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arseny Kapoulkine</title>
		<link>http://msinilo.pl/blog/?p=425&#038;cpage=1#comment-16108</link>
		<dc:creator>Arseny Kapoulkine</dc:creator>
		<pubDate>Tue, 08 Sep 2009 05:27:51 +0000</pubDate>
		<guid isPermaLink="false">http://msinilo.pl/blog/?p=425#comment-16108</guid>
		<description>Installing VC2008 redist did not help; downloading and registering (via regsvr32) msdia80.dll did not help either.</description>
		<content:encoded><![CDATA[<p>Installing VC2008 redist did not help; downloading and registering (via regsvr32) msdia80.dll did not help either.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
