<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 4, 2015 at 6:22 AM, Stephan Bergmann <span dir="ltr"><<a href="mailto:sbergman@redhat.com" target="_blank">sbergman@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 11/04/2015 12:03 PM, Norbert Thiebaud wrote:<br></span><span class="">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
imo intentional mis-alignment should be heavily documented as such.<br>
</blockquote>
<br></span>
I would assume "non-optimal" padding to occur frequently enough to just not care about it, unless there is indication that it severely affects performance.  Padding requirements can vary among platforms (e.g., due to differences in integer width types or differences in typedefs) and over time (e.g., when a member changes type or a member's type changes).  (And reordering members for tighter packaging can even negatively improve execution speed in various ways.)  So I would rather assume cases to be heavily documented where order is deliberately chosen to avoid padding.<div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div>It seems to me bit-fields are a bit overused. We should only need it in the most heavily instantiated of classes and where there are too many flags to make it worthwhile. For all other cases we're paying a cost in terms of performance and maintainability with little footprint gains. As noted already, padding will waste space if not intentionally accounted for. Of course member reordering to avoid padding can make readability suffer as well (we already have heavy public/private interlacing with const/non-const pairs pages apart).</div><div><br></div><div>FWIW, I'd make most classes (esp. heavily used but not heavily instantiated) to be human-intuitive first, while, for those that can benefit, order members by size (largest first) and bitfields for flags.</div><div><br></div><div>In any case, optimizations like these should be documented, otherwise it's not obvious what's intentional and what's accidental.</div></div></div></div>