<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">There are ways to affect alignment and padding between struct members. (as seen in the #pragma below)<DIV><BR class="khtml-block-placeholder"></DIV><DIV>Citing a reference from wikipedia (sorry, it was easy to find)</DIV><DIV><A href="http://en.wikipedia.org/wiki/Data_structure_alignment">http://en.wikipedia.org/wiki/Data_structure_alignment</A></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><P style="margin-top: 0px; margin-right: 0px; margin-bottom: 6px; margin-left: 0px; "><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;">While there is no standard way of defining the alignment of structure members, some compilers use </SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><I>#pragma</I></SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"> directives to specify packing inside </SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;">source files. Here is an example:</SPAN></FONT></P><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-color: rgb(249, 249, 249); "><SPAN class="Apple-style-span" style="line-height: 11px;"><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;">#pragma pack(push)</SPAN></FONT><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;"> </SPAN></FONT><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;">/* push current alignment to stack */</SPAN></FONT></SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-color: rgb(249, 249, 249); "><SPAN class="Apple-style-span" style="line-height: 11px;"><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;">#pragma pack(1) </SPAN></FONT><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;"> </SPAN></FONT><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;">/* set alignment to 1 byte boundary */</SPAN></FONT></SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10.3px/normal Courier; background-color: rgb(249, 249, 249); min-height: 13px; "><SPAN class="Apple-style-span" style="line-height: 11px;"><BR></SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-color: rgb(249, 249, 249); "><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px;">struct MyPackedData</SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-color: rgb(249, 249, 249); "><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px;">{</SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-color: rgb(249, 249, 249); "><SPAN class="Apple-style-span" style="line-height: 11px;"><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;"> </SPAN></FONT><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;">char Data1;</SPAN></FONT></SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-color: rgb(249, 249, 249); "><SPAN class="Apple-style-span" style="line-height: 11px;"><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;"> </SPAN></FONT><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;">long Data2;</SPAN></FONT></SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-color: rgb(249, 249, 249); "><SPAN class="Apple-style-span" style="line-height: 11px;"><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;"> </SPAN></FONT><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;">char Data3;</SPAN></FONT></SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-color: rgb(249, 249, 249); "><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px;">};</SPAN></FONT></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10.3px/normal Courier; background-color: rgb(249, 249, 249); min-height: 13px; "><SPAN class="Apple-style-span" style="line-height: 11px;"><BR></SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; background-color: rgb(249, 249, 249); "><SPAN class="Apple-style-span" style="line-height: 11px;"><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;">#pragma pack(pop) </SPAN></FONT><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;"> </SPAN></FONT><FONT class="Apple-style-span" face="Courier" size="3"><SPAN class="Apple-style-span" style="font-size: 10.3px; line-height: normal;">/* restore original alignment from stack */</SPAN></FONT></SPAN></DIV><P style="margin-top: 0px; margin-right: 0px; margin-bottom: 6px; margin-left: 0px; "><SPAN class="Apple-style-span" style="line-height: 19px;"><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px; line-height: normal;">This structure would have a compiled size of </SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px; line-height: normal;"><B>6 bytes</B></SPAN></FONT><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px; line-height: normal;">. The above directives are available in compilers from </SPAN></FONT></SPAN><A href="http://en.wikipedia.org/wiki/Microsoft"><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><FONT class="Apple-style-span" color="#0029B9">Microsoft</FONT></SPAN></FONT></A><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;">, </SPAN></FONT><A href="http://en.wikipedia.org/wiki/Borland"><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><FONT class="Apple-style-span" color="#0029B9">Borland</FONT></SPAN></FONT></A><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;">, </SPAN></FONT><A href="http://en.wikipedia.org/wiki/GNU"><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><FONT class="Apple-style-span" color="#0029B9">GNU</FONT></SPAN></FONT></A><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"> and many others.</SPAN></FONT></P><P style="margin-top: 0px; margin-right: 0px; margin-bottom: 6px; margin-left: 0px; "><FONT class="Apple-style-span" size="3"><SPAN class="Apple-style-span" style="font-size: 12.7px;"><BR class="khtml-block-placeholder"></SPAN></FONT></P><DIV>- David</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR><DIV><DIV>On May 3, 2007, at 5:22 PM, Måns Rullgård wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Loren Merritt <<A href="mailto:lorenm@u.washington.edu">lorenm@u.washington.edu</A>> writes:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">On Thu, 3 May 2007, Fejes Dávid wrote:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Memory is never allocated for h->dequant8_mf, h->quant8_mf and</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">h->unquant8_mf.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">x264_cqm_init (in common/set.c) will upload this matrices with data,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">but it doesn't allocates any memory before that for these pointers. In</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">my build it causes general protection fault (or simply it mess up</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">another variables). If I paste the corresponding x264_memalloc</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">function calls onto the beginning of the x264_cqm_init, it goes well.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">If I'm wrong, please let me know it. I've downloaded x264 at</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">22.07.2007 from the trunk, excuse me if you have corrected this.</DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Does this patch give an assert failure?</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">If so, I'll have to rethink my assumptions about compilers. Though I</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">don't see how to fix it without adding code complexity.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">If not, I can't see how else it would break.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space"> </SPAN>assert((void*)&h-><SPAN class="Apple-converted-space"> </SPAN>quant4_mf[4] == (void*)&h-><SPAN class="Apple-converted-space"> </SPAN>quant8_mf[0]);</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space"> </SPAN>assert((void*)&h->dequant4_mf[4] == (void*)&h->dequant8_mf[0]);</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space"> </SPAN>assert((void*)&h->unquant4_mf[4] == (void*)&h->unquant8_mf[0]);</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space"> </SPAN>assert((void*)&h->quant4_bias[4] == (void*)&h->quant8_bias[0]);</DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">There's no guarantee that those conditions are true.<SPAN class="Apple-converted-space"> </SPAN>The compiler is</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">allowed to add padding between any struct members.<SPAN class="Apple-converted-space"> </SPAN>If you need these</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">arrays to be contiguous you could declare them as a single array and</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">initialise two pointers into it.<SPAN class="Apple-converted-space"> </SPAN>That said, I'd be surprised if any</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">compiler actually added any padding here.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">--<SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Måns Rullgård</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:mans@mansr.com">mans@mansr.com</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">--</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">This is the x264-devel mailing-list</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">To unsubscribe, go to: <A href="http://developers.videolan.org/lists.html">http://developers.videolan.org/lists.html</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> </BLOCKQUOTE></DIV><BR></DIV></BODY></HTML>