QVariant 内部如何工作?
我想知道,QVariant 如何在内部存储 int、QMap、QList...
我的意思是内部数据结构/实现是什么?在 QVariant 中存储和检索类型(int、float)的开销是多少?
I want to know, How QVariant can internally stores, int, QMap, QList,...
I mean what is the internal data-structure/Implementation? What is the overhead of storing and retrieving types (int, float) in QVariant?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速浏览一下代码就会发现,
QVariant
基本上是几个基本类型(int
、float
)的联合
等),一个 QObject 指针,以及一个用于非QObject
和非原语的任何其他内容的void*
指针。还有一个类型数据成员,允许它知道当前实际存储的内容。开销似乎并不比存储到结构体的成员、检查类型兼容性并可能进行转换(例如 int 到 float)多多少A quick look at the code reveals that a
QVariant
is basically aunion
of several primitive types (int
,float
etc'), aQObject
pointer, and avoid*
pointer for anything else that is not aQObject
and not a primitive. There is also a type data member that allows it to know what's actually currently stored there. The overhead appears to be not much more than storing to a member of a struct, checking that for type compatibility and possibly making a conversion (int to float for instance)