Qt容器的大小:QMap是否比Qlist大得多? [英] Size of Qt containers: is QMap much larger than Qlist?

查看:815
本文介绍了Qt容器的大小:QMap是否比Qlist大得多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在开发一种在3D空间中映射信息的软件.我使用容器保存此信息.我使用的容器是


I am developing a software which maps information in 3D space. I use a container to hold this information. The container which I use is

 QList< QList< QMap<float, QList<quint16> > > > lidardata;

基本上是一个2D网格,代表一个矩形区域,其中每个单元格为1米x 1米,并且 QMap 在每个单元格中包含一个代表高度的键值以及一个位于四个位置的相关值的列表那个高度.这样,我可以存储五个值(高度+其他值).我在这样的循环中插入值( rown coln 分别是行索引和列索引)

which basically is a 2D grid representing a rectangular area where each cell is 1 meter x 1 meter, and in each cell the QMap contains a key value representing height and a list of four related values at that height. This way I can store five values (height + other values). I insert values in a loop like this (rown and coln are row and column indexes respectively)

QList<quint16> NEWLIST;

NEWLIST << (width*100.0) << (1000.0+sens*100.0) << (quint16)(intensity*1000.0) ;

lidardata[ rown ][ coln ].insert( heightValue, NEWLIST);

在使用这种方法之前,我没有使用QMap<float, QList<quint16>,而是使用了QList<quint16>并仅附加了5个值.
现在的问题是:运行程序会很快耗尽内存.完成第一个解决方案(QList而不是QMap)需要大约800Mb的内存,而现在它已耗尽(大约1.4 Gb),占总数据存储过程的75%.
有人可以确认使用QMap<float, QList<quint16>而不是QList<quint16>存储相同数量的信息确实需要更多的内存空间吗?

有人有限制空间的提示吗?如果什么都没发生,我将回到旧的解决方案.

Before this approach instead of using QMap<float, QList<quint16> I used QList<quint16> and just appending the 5 values.
Now the question is: running my program runs out of memory quite fast. It took up about 800Mb of memory to complete with the first solution (QList instead of QMap), now it runs out (at about 1.4 Gb) at 75% of the total data-storing process.
Can someone confirm that storing the same amount of information using QMap<float, QList<quint16> instead of QList<quint16> does require a lot more space in memory?

Does anyone have any hints to limit space? I will go back to the old solution if nothing comes up.

推荐答案

如评论中所述:

您的代码可能会受到原始痴迷.

尝试使用本教程中介绍的ValueObject修复程序解决您的问题:创建一个具有所有必需属性的类,并处理此类的实例,而不是维护嵌套的Qlist s和QMap s.

Try to solve your problem using the ValueObject fix stated in this tutorial : create a class with all needed attibutes, and work on instances of this class instead of maintaining nested Qlists and QMaps.

这篇关于Qt容器的大小:QMap是否比Qlist大得多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆