TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Padding is hard

74 点作者 spacey超过 9 年前

5 条评论

zeveb超过 9 年前
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 未加载
ajkjk超过 9 年前
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>
nkurz超过 9 年前
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.
hoprocker超过 9 年前
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 未加载
atria超过 9 年前
So there isn&#x27;t any equivalent to #pragma pack in Go? I&#x27;ll stick with C&#x2F;C++, thanks.
评论 #10362894 未加载