<div><div dir="auto">Hello Jesper,</div><div dir="auto"><br></div><div dir="auto">My binaries are an infinite stream of at least ~7500B each (include lot of floats).</div></div><div dir="auto"><br></div><div dir="auto">Packing the associated C struct will negatively  affect the performances I’m afraid.</div><div dir="auto"><br></div><div dir="auto">This is why I would like to align every field to its natural alignement if possible.</div><div dir="auto"><br></div><div dir="auto">/Frank</div><div dir="auto"><br></div><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">There is also an attribute, packed, which can be useful here:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><a href="https://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/Type-Attributes.html" target="_blank">https://gcc.gnu.org/onlinedocs/gcc-4.0.4/gcc/Type-Attributes.html</a></font><br></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><a href="http://www.catb.org/esr/structure-packing/" target="_blank">http://www.catb.org/esr/structure-packing/</a><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">If you are not too concerned about the efficiency, I would just pack the struct and send it over the wire. The problem with this on a modern CPU:</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">* While it packs tighter in your L1D cache, and this gives a speedup.</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">* It requires more instructions on-CPU to get alignment back in order.</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">* If multiple CPU threads access the data, you will end up bouncing between the L1D caches of the cores, and this is usually bad. With alignment, this can be avoided.</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif">My attack on the problem would be to pack first, then start measuring and see how much more I can get out of a solution as suggested by Mikael in this thread.</font></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 8, 2018 at 12:11 AM Sölvi Páll Ásgeirsson <<a href="mailto:solvip@gmail.com" target="_blank">solvip@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Can you use #pragma pack on the C structs?<div>You can then easily deconstruct them in a binary match</div><div><br></div><div>Regards</div><div>Sölvi<br><br><div id="m_4532373231521287510m_1908820073141157519AppleMailSignature" dir="ltr">Sent from my iPhone</div><div dir="ltr"><br>On 7 Dec 2018, at 21:02, Roger Lipscombe <<a href="mailto:roger@differentpla.net" target="_blank">roger@differentpla.net</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Fri, 7 Dec 2018 at 18:02, Frank Muller <<a href="mailto:frank.muller.erl@gmail.com" target="_blank">frank.muller.erl@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div dir="auto">Thanks Mikael.</div></div><div dir="auto">Any others thoughts ?</div></blockquote><div><br></div><div>I'm assuming that you've considered serializing and deserializing the data to an unpadded (or defined padding) format, but that you've presumably discounted it for performance reasons?</div><div><br></div><div>Just putting it out there in case someone's facing a similar issue, but has different constraints.</div><div><br></div><div>We once used XDR for this (with some kind of IDL-to-C converter, if I recall correctly). Some brief googling suggests that XDR is not dead yet.</div><div><br></div><div>Cheers,</div><div>Roger.</div></div></div>
</div></blockquote><blockquote type="cite"><div dir="ltr"><span>_______________________________________________</span><br><span>erlang-questions mailing list</span><br><span><a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a></span><br><span><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a></span><br></div></blockquote></div></div>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_4532373231521287510gmail_signature" data-smartmail="gmail_signature">J.</div>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div></div>