<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.12-alpha" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Controlling the Packing Alignment to Minimize Memory Consumption in C/C++</title>
	<link>http://www.codemaestro.com/reviews/7</link>
	<description>The Coding Experience</description>
	<pubDate>Thu, 20 Nov 2008 00:11:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.12-alpha</generator>

	<item>
		<title>by: Cedric Perthuis</title>
		<link>http://www.codemaestro.com/reviews/7#comment-17753</link>
		<pubDate>Sat, 02 Aug 2008 22:33:04 +0000</pubDate>
		<guid>http://www.codemaestro.com/reviews/7#comment-17753</guid>
					<description>As mentioned in the article, changing the packing will definitely decrease the performance and might increase the code size, which might not be acceptable. 

It could be worth mentioning that a simpler and more efficient practice is simply to order the members of the structure from the bigger storage size to the smaller. Most of the time, the amount of wasted space will only be at most once the size of the bigger type minus the size of the smaller type.

on the example given, reordering the parameters this way:
struct myPack
{
    int m_int;
    char m_char;
    char m_boolean:1;
};
gives the following memory layout:

[m_int, m_int, m_int, m_int, m_char, m_boolean, _, _]

that's 8 bytes instead of 12 and everything is still aligned as it should to maximize performance.</description>
		<content:encoded><![CDATA[<p>As mentioned in the article, changing the packing will definitely decrease the performance and might increase the code size, which might not be acceptable. </p>
<p>It could be worth mentioning that a simpler and more efficient practice is simply to order the members of the structure from the bigger storage size to the smaller. Most of the time, the amount of wasted space will only be at most once the size of the bigger type minus the size of the smaller type.</p>
<p>on the example given, reordering the parameters this way:<br />
struct myPack<br />
{<br />
    int m_int;<br />
    char m_char;<br />
    char m_boolean:1;<br />
};<br />
gives the following memory layout:</p>
<p>[m_int, m_int, m_int, m_int, m_char, m_boolean, _, _]</p>
<p>that&#8217;s 8 bytes instead of 12 and everything is still aligned as it should to maximize performance.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
