为什么二进制可执行文件的大小增加了相同代码块的不同量?
假设我有一个C ++程序,我使用G ++进行了编译。然后,我得到一个可执行文件,例如,该文件的大小为100 kb。然后,我添加了几行C ++代码,然后再次编译,可执行文件的大小增加到101 kb。然后,我添加完全相同的 C ++代码的块,并第三次编译。这次可执行文件已增加到106 KB。为什么相同的代码有时会增加可执行文件的大小,而另一个时间会增加呢?
同样,只有每隔几次就会发生大幅度增长,大多数时候它会增加, small ,数量。
Let's say I have a C++ program and I compile it using g++. I then get an executable file which, as an example, has a size of 100 kb. I then add a couple of lines of C++ code and compile again and the size of the executable has increased to 101 kb. Then I add the exact same block of C++ code and compile a third time. This time the executable has increased to 106 kb. Why does it happen that the same code sometimes increases the size of the executable by one amount, and another time something much greater?
Also the big increase only happens every couple of times, most of the time it increases by the same, small, amount.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导致二进制的尺寸变化与代码尺寸变化不线性的原因有多种。如果启用了某种优化,则尤其如此。
即使在调试模式下(无优化),以下内容也可能导致这种情况:
如果启用了优化,由于可能的优化策略,它会变得更加令人困惑:
这些只是许多可能的原因,可能还有更多原因。
There are a variety of reasons why the size change of the resulting binary is not linear with the code size change. This is particularly true if some kind of optimization is enabled.
Even in debug mode (no optimizations), the following things could cause this to happen:
If optimizations are enabled, it gets even more confusing, due to possible optimization strategies:
These are just a bunch of possible reasons, there might be many more.