VC2008中返回值优化
是否还有其他技术可以与 VC2008 一起使用,例如 RVO(返回值优化)或 NRVO(命名返回值优化)?
Is there other technique like RVO (return value optimization) or NRVO (named return value optimization) that can be use with VC2008?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我是你,我不会太担心这些优化。 除此之外,它们不可携带。
如果您担心编写高效的 C++ 代码,首要规则是完全避免复制。 确保在所有可能的地方使用参考,但不要尝试在不可能的地方使用它们。 之后,有时您实际上需要一个新值 - 例如,作为operator+() 实现的返回值。
I wouldn't worry too much about those optimisations if I were you. Apart from anything else, they are not portable.
If you are worried about writing efficient C++ code, the number one rule is to avoid copying altogether. Make sure you use reference in all places where they are possible, but don't try to use them where they are not. After, all sometimes you actually need a new value - as the return value for implementations of operator+(), for example.
也许这可能对您有帮助。
但通常是编译器进行此类优化,而不是您。
Maybe this may help you.
But typically it's the compiler who does such kind of optimization, not you.