What is the performance overhead of std::function?(std::function 的性能开销是多少?)
问题描述
我在论坛上听说使用 std::function<>
会导致性能下降.这是真的吗?如果是真的,是不是性能下降很大?
I heard on a forum using std::function<>
causes performance drop. Is it true? If true, is it a big performance drop?
推荐答案
您可以从 boost 的参考资料中找到信息:通过 boost::function 调用会产生多少开销? 和 性能
You can find information from the boost's reference materials: How much overhead does a call through boost::function incur? and Performance
这并不能确定增强功能的是或否".鉴于程序的要求,性能下降可能是可以接受的.通常情况下,程序的某些部分不是性能关键的.即便如此,它也可能是可以接受的.这只能由您来确定.
This doesn't determine "yes or no" to boost function. The performance drop may be well acceptable given program's requirements. More often than not, parts of a program are not performance-critical. And even then it may be acceptable. This is only something you can determine.
对于标准库版本,标准只定义了一个接口.使其工作完全取决于个人实现.我想会使用与 boost 函数类似的实现.
As to the standard library version, the standard only defines an interface. It is entirely up to individual implementations to make it work. I suppose a similar implementation to boost's function would be used.
这篇关于std::function 的性能开销是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:std::function 的性能开销是多少?


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 我有静态或动态 boost 库吗? 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01