为什么完整的“ constexpr”启用数据结构会导致编译的代码更大?
at 这个启用每个数据结构(我猜这意味着使每个字段和函数constexpr)可能会导致更大的代码“因为这会导致更多的数据结构被编译到代码中,因此您在该代码中有更多数据数据细分比在运行时计算的内容相比“这句话是他在此时间邮票上实际说过的内容以及他最后所说的内容的结合,以回答有关此主题的问题的回答)。
我真的不明白这意味着什么。为什么ConstexPR数据结构会编译比非constexpr数据结构更大?有人有一个实际示例显示这一点吗?
At this moment of Jason Turner's 2016 CppCon talk "Practical Performance Practices", he mentions that full constexpr enabling of every data structure that can be (I'm guessing that means making every field and function constexpr that can be) can result in bigger code "because this causes more data structures to be compiled into your code so you have more data in the data segment than something that would be calculated at runtime" (this quote is kind of a combination of what he actually said at this time stamp and what he said at the end as an answer to a question about this topic).
I don't really understand what that means. Why would constexpr data structures compile to be bigger than non-constexpr data structures? Does anyone have an actual example that shows this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在微控制器上实施7位环状冗余检查(CRC)算法时,我发现提前构建256个字节查找表非常方便,并使用类似的代码:
因此,如果您转动
crc_table
进入constexpr
在编译时计算的东西,您的工具链将必须在可执行文件中存储一个256字节的表,从而占用空间。它也能够删除用于生成CRC表的代码,但是如果该代码的机器指令少于256个字节,那么我希望可执行文件会变得更大。When implementing a 7-bit cyclic redundancy check (CRC) algorithm on a microcontroller, I find it handy to build a 256-byte lookup table ahead of time, with some code like this:
So if you turn
crc_table
into aconstexpr
thing that gets computed at compile time, your toolchain would have to store a 256-byte table in your executable, which takes up space. It would also be able to remove the code for generating the CRC table, but if the machine instructions for that code take less than 256 bytes, then I'd expect the executable to get bigger.