Measure Heap Memory allocated for QList?
-
Hi,
I have a QTableWidget in my Main Window. I have created QTableWidgetItem from heap & set them for each cell.
Due to some reasons I am storing the contents of the item of each cell in individual QString objects which are also created of the heap.
I am maintaining the associativity by using QList for each row & another QList to store references of all such QList's. Thus it is something like this:@QList <QList <QString *> *> *mycells;@
Now I can access the QString for each cell by:
@for(int i = 0; i < mycells->size(); i++)
{
QList <QString *> *rows = (*mycells)[i];
for(int j = 0; j < rows->size(); j++)
{
QString *mystr = (*rows)[j];
}
}@If anybody can tell whether there is anything wrong in my approach, then please let me know.
OK, so now the problem is that when I increase the rows from 0 & columns from 0 for the table to, rows = 1000 & columns = 1000 i.e. there are 1000000 cells then my application is showing increase in memory by ~200MB in the task manager.
Now I want to test how much of that is due to @QList mycells@.
How do I do that?
Ideally how much memory would be required for a QTableWidget including all the QTableWidgetItem's & Horizontal & Vertical Headers of size 1000x1000? -
we had such a questions a few days ago "here":http://qt-project.org/forums/viewthread/27259/.
-
Hi there.
What you ask is almost impossible te answer! A QList is as big as the members in it, but you guessed it already. The QString will automatic allocate more memory when needed if more text needs te be stored in the cell. So, no, there is not a complete valid answer for your question.
About the first part, it seems that you are manually creating a sort of Model/View setup. The model/View topology was created to avoid what you are doing ;-)
Maybe read the tutorial:
"Model/View link":http://qt-project.org/doc/qt-4.8/model-view-programming.htmlAt first the QTableWidget will do just fine, but when getting to know the MVC it is really easy to use to support massive amounts of data without difficult update/check routines etc.
Hope this helps a bit