0


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.

demonplus
  • 5,613
  • 12
  • 49
  • 68
Francesco
  • 47
  • 1
  • 7
  • 1
    Is there any reason why you're using so many lists and a map in the first place? If you want to represent a cell with data, why not create a cell class with member variables of xpos / ypos and have a variable of an object to the height map data? Then just use one list of cell items. This is going to be much quicker than lists within lists and take up less memory. – TheDarkKnight May 14 '13 at 08:51
  • That helped quite a bit, nested QLists were really not necessary. I kept my map and used a class for holding a 1-D array of QMaps which is just a continous representation of my 2-D space where position in 2-D is referenced by [rowNumber * rowTotNumber + colNumber]. Still my data is very large, and the only solution will be to find disk-based containers. Thank you! – Francesco May 15 '13 at 07:40

1 Answers1

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.

kiriloff
  • 25,609
  • 37
  • 148
  • 229