Results 1 to 2 of 2

Thread: qvector.h, line 538: Out of memory, std::bad_alloc

  1. #1
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default qvector.h, line 538: Out of memory, std::bad_alloc

    Hi,
    we provide a software for our customers that can show either a graph or a table with
    the measured values at a specific time. When i have big data and switch to table view
    our software crashed with the message:

    Qt Code:
    1. In file ..\..\include/QtCore/../../src/corelib/tools/qvector.h, line 538: Out of memory
    2. Invalid parameter passed to C runtime function.
    3. Invalid parameter passed to C runtime function.
    4. exited with code 3
    To copy to clipboard, switch view to plain text mode 

    Our software crashes (Release) at around 1,8 GB memory usage (from Windows 7 task manager).

    qvector.h (Qt 5.6.2)
    Qt Code:
    1. template <typename T>
    2. void QVector<T>::reallocData(const int asize, const int aalloc, QArrayData::AllocationOptions options)
    3. {
    4. Q_ASSERT(asize >= 0 && asize <= aalloc);
    5. Data *x = d;
    6.  
    7. const bool isShared = d->ref.isShared();
    8.  
    9. if (aalloc != 0) {
    10. if (aalloc != int(d->alloc) || isShared) {
    11. QT_TRY {
    12. // allocate memory
    13. x = Data::allocate(aalloc, options);
    14. Q_CHECK_PTR(x); // THIS IS LINE 538
    To copy to clipboard, switch view to plain text mode 

    and this is the code to fill the table
    Qt Code:
    1. for(int u=itemList.at(i)->idx;u<itemList.at(i)->mData->values.size();u++){
    2.  
    3. if(ui->tableWidget->rowCount() < u+1)
    4. ui->tableWidget->setRowCount(u+1);
    5.  
    6. QTableWidgetItem* itemt = new QTableWidgetItem(loc.toString(itemList.at(i)->mData->timestamps.at(u)));
    7. itemt->setTextColor(itemList.at(i)->color);
    8. ui->tableWidget->setItem(u,(i+1)*2-2,itemt);
    9.  
    10. QString tmp;
    11. if(itemList.at(i)->mData->errorFlag.length() > u){
    12. if(itemList.at(i)->mData->errorFlag.at(u) == 0){
    13.  
    14. tmp = loc.toString(itemList.at(i)->mData->values.at(u)*setManager->getPressureFactor());
    15. }
    16. else if(itemList.at(i)->mData->errorFlag.at(u) & errflgUR) // Error UR
    17. tmp = tr("Underrange");
    18. else if(itemList.at(i)->mData->errorFlag.at(u) & errflgOR) // Error OR
    19. tmp = tr("Overrange");
    20. else if(itemList.at(i)->mData->errorFlag.at(u) & errflgSEDIS ) // Error SEDIS
    21. tmp = tr("Sensor disabled");
    22. }
    23.  
    24. itemp->setTextColor(itemList.at(i)->color);
    25. ui->tableWidget->setItem(u,(i+1)*2-1,itemp);
    26.  
    27. itemList.at(i)->idx = u;
    28. }
    To copy to clipboard, switch view to plain text mode 

    Has someone any idea to improve our code or any other help is welcome?
    HappyCoder

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,716
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: qvector.h, line 538: Out of memory, std::bad_alloc

    What did you try so far?
    For example, did you try to run it with a small test data set?
    If you run a debug build in a debugger, does it behave differently i.e doesn't crash, or crashes somewhere else?
    If it still crashes while in debugger, have a look at the calls stack, and trace the last call in your own code, see if you get clues there.
    Also, make sure you are not having an endless recursion, which also could crash with alloc memory errors.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. std::bad_alloc crash
    By Urthas in forum General Programming
    Replies: 2
    Last Post: 5th December 2016, 17:26
  2. QtConcurrent std::bad_alloc
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2013, 06:23
  3. Memory aligned QVector().data()
    By sto in forum Qt Programming
    Replies: 10
    Last Post: 19th November 2010, 09:30
  4. QFile::open throws std::bad_alloc for no obvious reason
    By nateriver in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2009, 06:10
  5. Memory allocation failure and crash in QVector
    By ashatilo in forum Qt Programming
    Replies: 16
    Last Post: 20th October 2007, 23:27

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.