TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Padding is hard

74 pointsby spaceyover 9 years ago

5 comments

zevebover 9 years ago
Given how much Go already does for one—and given the static nature of Go binaries—is there any reason why the compiler shouldn&#x27;t reorder structs so that they take the least space possible?<p>I can see that that would prevent one from reliably dumping memory to disk and then re-reading it, but It&#x27;s hardly reliable to do that <i>anyway</i>. One should be using an encoding anyway…
评论 #10360960 未加载
评论 #10361093 未加载
评论 #10360943 未加载
评论 #10360849 未加载
评论 #10361112 未加载
评论 #10361307 未加载
ajkjkover 9 years ago
If you&#x27;re like me and had no idea what<p>_ struct{} &#x2F;&#x2F; to prevent unkeyed literals<p>means, some explanation turns up here: <a href="https:&#x2F;&#x2F;groups.google.com&#x2F;forum&#x2F;#!topic&#x2F;golang-nuts&#x2F;NSjVW82i0mY" rel="nofollow">https:&#x2F;&#x2F;groups.google.com&#x2F;forum&#x2F;#!topic&#x2F;golang-nuts&#x2F;NSjVW82i...</a>
nkurzover 9 years ago
The article mentions that the &quot;Go spec says the address of a struct’s fields must be naturally aligned&quot;, and seems to take for granted that is necessary for speed. A separate question would be whether it actually helps performance.<p>For modern x64&#x2F;x86 the answer seems be to &quot;no&quot;: <a href="http:&#x2F;&#x2F;lemire.me&#x2F;blog&#x2F;2012&#x2F;05&#x2F;31&#x2F;data-alignment-for-speed-myth-or-reality&#x2F;" rel="nofollow">http:&#x2F;&#x2F;lemire.me&#x2F;blog&#x2F;2012&#x2F;05&#x2F;31&#x2F;data-alignment-for-speed-my...</a><p>Would it make sense for the Go spec to drop the alignment requirement? I&#x27;d think that a smaller memory footprint would be the better choice, and I&#x27;d think that interoperability would be better served by allowing arbitrary alignments.
hoprockerover 9 years ago
Side question: who is in that animated gif about a quarter of the way down the page (fingers to temples, starbursts in background)? I see that around on dev blogs quite a bit.
评论 #10361297 未加载
评论 #10362596 未加载
atriaover 9 years ago
So there isn&#x27;t any equivalent to #pragma pack in Go? I&#x27;ll stick with C&#x2F;C++, thanks.
评论 #10362894 未加载