Results 1 to 17 of 17

Thread: How big is big for a qtable (2 m rows is to big) ?

  1. #1
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Unhappy How big is big for a qtable (2 m rows is to big) ?

    I am having a problem trying to print a vector of 2 000 000 rows x 4 columns of dates and float and display it into a qTable. Around row 400 000 rows, the application cores. with the following error message :

    std::bad_alloc()

    Bizarrely enough :
    Qt Code:
    1. myTable->setNumRows(2000 000);
    2. myTable->setNumCols(4);
    To copy to clipboard, switch view to plain text mode 

    is fine,

    but the program cores in the middle of this loop :

    Qt Code:
    1. for(int line=0; line < 3000000; ++line)
    2. {
    3. ....
    4. myTable->setText(line,0,"dummy string");
    5. ....
    6. }
    To copy to clipboard, switch view to plain text mode 

    I have 2 gig or RAM + 4 gig of swap, so I I do not think that I run out of memory.

    Does anybody have an idea ?

    Thanks.

    Tuan.
    Last edited by wysota; 27th January 2007 at 22:36. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Sorry for the typo, of course, one should read
    for(int line=0; line < 2000000; ++line)

    One more precision : when I just do a qWarning of the data, all works fine, only when I try to setText does it core, so the bug is really localized to the table fillup.

    Thanks.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How big is big for a qtable (2 m rows is to big) ?


  4. #4
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Code :

    Qt Code:
    1. void Form1::populateTable()
    2. {
    3. myTable->setNumRows(2000000);
    4. myTable->setNumCols(3);
    5. for (int i=0; i < 2000000; ++i)
    6. {
    7. for (int j=0; j < 3; ++j)
    8. {
    9. myTable->setText(i,j,QString::number(i));
    10. qWarning("Line = " + QString::number(i) + " Col = " + QString::number(j));
    11. }
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Backtrace :

    #0 0x289aeecb in kill () from /lib/libc.so.6
    #1 0x288d4236 in raise () from /lib/libpthread.so.2
    #2 0x289adb78 in abort () from /lib/libc.so.6
    #3 0x2887e3f4 in __gnu_cxx::__verbose_terminate_handler () from /usr/local/lib/gcc-4.1.2/libstdc++.so.6
    #4 0x2887c15c in __cxxabiv1::__terminate () from /usr/local/lib/gcc-4.1.2/libstdc++.so.6
    #5 0x2887c1a4 in std::terminate () from /usr/local/lib/gcc-4.1.2/libstdc++.so.6
    #6 0x2887c2ac in __cxa_throw () from /usr/local/lib/gcc-4.1.2/libstdc++.so.6
    #7 0x2887c72a in operator new () from /usr/local/lib/gcc-4.1.2/libstdc++.so.6
    #8 0x28585372 in QString::setLength () from /usr/X11R6/lib/libqt-mt.so.3
    #9 0x28585718 in QString::grow () from /usr/X11R6/lib/libqt-mt.so.3
    #10 0x28586e33 in QString::operator+= () from /usr/X11R6/lib/libqt-mt.so.3
    #11 0x0804da65 in operator+ (s1=@0xbfbfe074, s2=0x804e778 " Col = ") at qstring.h:1046
    #12 0x0804d700 in Form1::populateTable (this=0xbfbfe8c8) at form1.ui.h:23
    #13 0x0804e3e7 in Form1::qt_invoke (this=0xbfbfe8c8, _id=60, _o=0xbfbfe140) at .moc/moc_form1.cpp:84
    #14 0x282e16a8 in QObject::activate_signal () from /usr/X11R6/lib/libqt-mt.so.3
    #15 0x282e1d19 in QObject::activate_signal () from /usr/X11R6/lib/libqt-mt.so.3
    #16 0x285e8a50 in QButton::clicked () from /usr/X11R6/lib/libqt-mt.so.3
    #17 0x2836d95e in QButton::mouseReleaseEvent () from /usr/X11R6/lib/libqt-mt.so.3
    #18 0x283142bb in QWidget::event () from /usr/X11R6/lib/libqt-mt.so.3
    #19 0x28285549 in QApplication::internalNotify () from /usr/X11R6/lib/libqt-mt.so.3
    #20 0x28285805 in QApplication::notify () from /usr/X11R6/lib/libqt-mt.so.3
    #21 0x28226f23 in QETWidget::translateMouseEvent () from /usr/X11R6/lib/libqt-mt.so.3
    #22 0x28225ea3 in QApplication::x11ProcessEvent () from /usr/X11R6/lib/libqt-mt.so.3
    #23 0x282375f0 in QEventLoop::processEvents () from /usr/X11R6/lib/libqt-mt.so.3
    #24 0x2829993f in QEventLoop::enterLoop () from /usr/X11R6/lib/libqt-mt.so.3
    #25 0x28299898 in QEventLoop::exec () from /usr/X11R6/lib/libqt-mt.so.3
    #26 0x28284884 in QApplication::exec () from /usr/X11R6/lib/libqt-mt.so.3
    #27 0x0804cd9d in main (argc=Cannot access memory at address 0x0
    ) at main.cpp:10

    I'm confused. Thanks for your help.
    Last edited by wysota; 27th January 2007 at 22:34. Reason: Disabled smileys and fixed missing [code] tags

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Quote Originally Posted by tuan View Post
    I have 2 gig or RAM + 4 gig of swap, so I I do not think that I run out of memory.
    This is not so obvious. First of all on 32bit systems you can't have more than 4G of memory "active" at once (it cannot be addressed) so the obvious upper limit on resources for the application is 4GB, more swap won't help. Furthermore you can have system limits per process set. Obiously operator new throws a bad_alloc exception which means the allocator can't allocate memory the process requires. Of course a completely different thing is why this happens. Probably QTable allocates some extra memory when growing which exceeds some limit and causes an exception to be thrown.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Could you comment out that qWarning() and try valgrind --tool=massif --- this should tell you how much memory your program really uses.

    Which Qt version do you use exactly?

  7. #7
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Thanks for your time and advice....

    I'm using Qt 3.3.6 and gcc 4.1 on FreeBSD 6.2

    Here is the output of valgrind. It is still gibberish for me at this time (newbie in Valgrind)....

    $ valgrind --tool=massif /home/tuan/data/c++/test/huge_table/huge
    ==19668== Massif, a space profiler for x86-linux.
    ==19668== Copyright (C) 2003, Nicholas Nethercote
    ==19668== Using valgrind-2.1.2.CVS, a program supervision framework for x86-linux.
    ==19668== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward.
    ==19668== For more details, rerun with: -v
    ==19668==
    --19668-- INTERNAL ERROR: Valgrind received a signal 11 (SIGSEGV) - exiting
    --19668-- si_code=0xC Fault EIP: 0xB8028EE0 (); Faulting address: 0xBFCEBFFC

    valgrind: the `impossible' happened:
    Killed by fatal signal
    Basic block ctr is approximately 793900000
    ==19668== at 0xB802D8DD: (within /usr/local/lib/valgrind/stage2)
    ==19668== by 0xB802D8DC: (within /usr/local/lib/valgrind/stage2)
    ==19668== by 0xB802D8F4: vgPlain_core_panic (in /usr/local/lib/valgrind/stage2)
    ==19668== by 0xB8034360: (within /usr/local/lib/valgrind/stage2)

    sched status:

    Thread 1: status = Runnable, associated_mx = 0x0, associated_cv = 0x0
    ==19668== at 0x810390AF: operator new[](unsigned) (in /usr/local/lib/valgrind/vgpreload_massif.so)
    ==19668== by 0x815401C8: QString::QString(QChar const*, unsigned) (in /usr/X11R6/lib/libqt-mt.so.3)
    ==19668== by 0x8152DA95: qulltoa(unsigned long long, int, QLocalePrivate const&) (in /usr/X11R6/lib/libqt-mt.so.3)
    ==19668== by 0x8152E1AD: QLocalePrivate::longLongToString(long long, int, int, int, unsigned) const (in /usr/X11R6/lib/libqt-mt.so.3)

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Quote Originally Posted by tuan View Post
    --19668-- INTERNAL ERROR: Valgrind received a signal 11 (SIGSEGV) - exiting
    Too bad, Valgrind got killed. Reduce the number of rows to 100000 and try again or better prepare a minimal compilable example, so we can test it too.

    There are three possibilites:
    • QTable eats a lot of space,
    • you suffer from memory fragmentation,
    • there's a memory leak somewhere.

  9. #9
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Here is the code to be compiled :

    On my 2 GB machine, for numRows = 750000, it works fine, but for numRows=850000, I get the following message :

    terminate called after throwing an instance of 'std::bad_alloc'
    what(): St9bad_alloc

    Jacek, I tried valgrind --tools=massif mycode, however, it cored. I think that this might be due to the valgrind port under FreeBSD which somehow is not very stable.

    Thanks a lot for your help.


    Qt Code:
    1. #include <qapplication.h>
    2. #include <qtable.h>
    3.  
    4.  
    5. const int numRows = 850000;
    6. const int numCols = 3;
    7.  
    8. int main( int argc, char **argv )
    9. {
    10. QApplication app( argc, argv );
    11.  
    12. QTable table( numRows, numCols );
    13.  
    14. for ( int i = 0; i < numRows; ++i )
    15. {
    16. for (int j = 0; j < numCols; ++j)
    17. {
    18. table.setText( i, j, QString::number(i) );
    19. }
    20. }
    21.  
    22. app.setMainWidget( &table );
    23. table.show();
    24. return app.exec();
    25. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 28th January 2007 at 17:04. Reason: missing [code] tags

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    I managed to run the application with 850k rows.

    According to top it occupied ~0.6GB of memory. I have 512MB of physical RAM and 1,2GB of swap on my system (top reported about 53% memory usage 428virt + 224res).

    With 850k rows and 3 columns it gives 2550 cells + headers. It gives an average of ~200kB per cell. Of course you should substract all other objects from above figures (~6MB are occupied by the libraries themselves).

    My guess is that you have some limits per process set in your system.

    What does "ulimit -a" return for you?

  11. The following user says thank you to wysota for this useful post:

    tuan (28th January 2007)

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Quote Originally Posted by tuan View Post
    Jacek, I tried valgrind --tools=massif mycode, however, it cored. I think that this might be due to the valgrind port under FreeBSD which somehow is not very stable.
    Luckily it worked on my system. It seems that there are two problems. First of all QTableItems take a lot of space and there is a problem with memory fragmentation --- note the size of "heap-admin" strips.

    I've managed to reduce memory size a bit by removing all of those null pixmaps that were created for each table item, but probably it won't be enough for you. Better try not to use QTableItems at all, as described here: http://doc.trolltech.com/3.3/qtable....n-large-tables.

    Qt Code:
    1. int main( int argc, char **argv )
    2. {
    3. QApplication app( argc, argv );
    4.  
    5. QTable table( numRows, numCols );
    6.  
    7. for ( int i = 0; i < numRows; ++i )
    8. {
    9. for (int j = 0; j < numCols; ++j)
    10. {
    11. QTableItem *item = new QTableItem( &table,
    12. QTableItem::OnTyping, QString::number(i), p );
    13. table.setItem( i, j, item );
    14. }
    15. }
    16.  
    17. app.setMainWidget( &table );
    18. table.show();
    19.  
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    You can get even better results with:
    Qt Code:
    1. for ( int i = 0; i < numRows; ++i )
    2. {
    3. QString s( QString::number( i ) );
    4. for (int j = 0; j < numCols; ++j)
    5. {
    6. QTableItem *item = new QTableItem( &table,
    7. QTableItem::OnTyping, s, p );
    8. table.setItem( i, j, item );
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    But still heap administration will cost you a lot, because you create a lot of small objects.

  14. The following user says thank you to jacek for this useful post:

    tuan (28th January 2007)

  15. #13
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Thanks a bunch to Jacek and Wysota. I will try to follow your advice tomorrow. Otherwise, if it still does not work, I will probably try and divide the display my vector by slices of 100 K lines (the table displays the content of a 2 million lines vector).

    Best regards and thank you both for your time and expertise.

    Tuan.

  16. #14
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Otherwise, to answer Wysota :

    $ ulimit -a
    cpu time (seconds, -t) unlimited
    file size (512-blocks, -f) unlimited
    data seg size (kbytes, -d) 524288
    stack size (kbytes, -s) 65536
    core file size (512-blocks, -c) unlimited
    max memory size (kbytes, -m) unlimited
    locked memory (kbytes, -l) unlimited
    max user processes (-u) 5547
    open files (-n) 11095
    virtual mem size (kbytes, -v) unlimited
    sbsize (bytes, -b) unlimited

  17. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Quote Originally Posted by tuan View Post
    data seg size (kbytes, -d) 524288
    stack size (kbytes, -s) 65536
    You have a 512MB limit on data size and 64MB limit on stack size. The former causes the exception to be thrown. You have to keep below that limit or ask your sysadmin to remove it. Of course the first solution is much better The same thing causes valgrind to collapse.

  18. #16
    Join Date
    Jan 2007
    Posts
    8
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Thanks Wysota ! Now, I have tried to do something like this :

    $ ulimit -s unlimited
    ulimit: bad limit: Operation not permitted

    Can you please tell me how to set the heap size to unlimited (I'm the administrator for my machine) ? I've searched on the net without really getting relevant infos on that. Thanks a lot.

  19. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How big is big for a qtable (2 m rows is to big) ?

    Quote Originally Posted by tuan View Post
    $ ulimit -s unlimited
    ulimit: bad limit: Operation not permitted
    You have to be root to do that. If any user could alter the limit then there wouldn't be much sense in setting that limit in the first place.

    I suggest you follow Jacek's hints though, you'll gain more by reducing memory requirements of your application than by lifing resource limits.

Similar Threads

  1. Remove selected rows from a QTableView
    By niko in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2016, 12:49
  2. Replies: 1
    Last Post: 28th September 2006, 06:21
  3. Replies: 10
    Last Post: 24th August 2006, 09:35
  4. QTableView number of rows and scrollbar issue
    By jnk5y in forum Qt Programming
    Replies: 3
    Last Post: 1st March 2006, 06:55
  5. QTable..Vs.. QListView
    By :db:sStrong in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 21:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.