Size of Qt containers: is QMap much larger than Qlist?

↘锁芯ラ 提交于 2019-12-11 19:19:53

问题



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;

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);

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.


回答1:


As mentionned in comment:

your code may suffer from Primitive Obsession.

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.



来源:https://stackoverflow.com/questions/16528424/size-of-qt-containers-is-qmap-much-larger-than-qlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!