问题描述
我最近发布了一个关于 QObject 在典型使用场景中的开销的问题,但不幸的是,该问题与另一个在技术上没有回答问题的问题重复.
I recently posted a question about the overhead of QObject in typical usage scenarios, but unfortunately the question got closed as a duplicate of another question that didn't technically answer the question.
更糟糕的是,礼貌地冲过去结束我的问题的仓促的撒玛利亚人"打断了我在运行了几次测试后刚刚完成打字的答案.由于我无法再在原始问题中发布我的发现,我将其发布在这里,以便其他可能需要该信息的人可以使用.
What is worse, the hasty "Samaritans" who politely rushed to close my question interrupted the answer I was just finishing typing after running a few tests. Since I can no longer post my findings in my original question, I'll post it here so it is available to others who might need that information.
推荐答案
很多人都暗示 QObject 很重,但并不清楚它到底有多重.所以我做了一些测量,不是很准确,所有数值都是近似值.
A lot of people have hinted at QObject being heavy, but without any clarity on how heavy is it exactly. So I did some measurements, not very accurate, all values are approximate.
- 未使用的 QObject ~160 字节
- 没有参数的单个自动连接 ~235 字节
- 2 个不带参数的自动连接 ~315 字节
- 3 个自动连接,1 个带有 3 个参数 ~400 字节
- 2 个自动连接,1 个排队,有 3 个参数 ~432 字节
这些数字应该考虑到我使用的是 64 位 Qt 版本.
Those numbers should take into account I am using a 64 bit Qt build.
所以,总而言之,QObject 的开销确实相当大.没有什么可以打喷嚏或过度使用.
So, in conclusion, the overhead of QObject is quite significant indeed. Nothing to sneeze at or overuse.
这篇关于QObject 到底有多重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!