問題描述
我最近發布了一個關于 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 到底有多重?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!