QObject 到底有多重?

2023-01-22C/C++开发问题
1

本文介绍了QObject 到底有多重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我最近发布了一个关于 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 到底有多重?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6