PDA

View Full Version : How to decrease the model size in memory?



mismael85
19th January 2011, 23:56
Hello every body,
I am using QAbstractTableModel to represent more than 4000,000 record, when I scroll down the view to the end the application size is increased in the memory from 50 MB to 111 MB.

QVariant SearchModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
switch(role)
{
case Qt::DisplayRole:
{
switch(index.column())
{
case 0: // serial
{
return index.row()+1;
}
break;
case 1: // text
{
return m_pSearchEngine->getHighlightedText(index.row(), false);
}
break;
case 2: // book name
{
return m_pSearchEngine->getBookName(index.row());
}
break;
case 3:
{
return m_pSearchEngine->getTitle(index.row());
}
break;
case 4: // part no
return m_pSearchEngine->getPartNo(index.row());
break;
case 5: // page no
return m_pSearchEngine->getPageNo(index.row());
break;
}
}
break;
}
return QVariant();
}
I examined the functions I used it just return strings.
How can I decrease the amount of memory that the model take?
Thank you

wysota
20th January 2011, 01:17
If you have 4M rows then if your memory footprint increases by 60M then it means on average each row cost you 15 bytes. I'd say it's not that bad. To reduce the footprint you can reduce the number of rows.

mismael85
20th January 2011, 09:44
This means that the data is stored in the view so that whenever the rows are increased the size is increased.

but I can not reduce the search results , but i can make an idea just like google search by displaying 100 row each time.

what is the widget suitable for this?

wysota
20th January 2011, 10:55
You can use any of the views available. Just limit your model. If you're worried about memory footprint, make sure you are not using QSortFilterProxyModel anywhere as it keeps an internal map of nodes in your base model.