Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QList bad_alloc error
Forum Updated to NodeBB v4.3 + New Features

QList bad_alloc error

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FreshZone
    wrote on last edited by
    #1

    Hello
    I need your help, I'm using an QList to which I want to append up to 860 million elements. So i worte this code to test it:
    @QList<qint16> myData;
    myData.reserve(860000000);
    for(qint32 a=0;a<860000000;a++)
    {
    myData.append(a);
    }
    qDebug()<<(float)myData.size()/1e6<<"Million entries";@

    But my program crashes (at line 2) and it get an error std::bad_alloc.

    So I tried the same with QVector:

    @ QVector<qint16> myData;
    myData.reserve(860000000);
    for(qint32 a=0;a<860000000;a++)
    {
    myData.append(a);
    }
    qDebug()<<(float)myData.size()/1e6<<"Million entries";@

    And I get the output from qDebug(): 860 Million entries.
    Can someone tell me why this works with QVector, but fails with QList? And if there is a way I still can use the QList container?

    860Million entries times 16bit equals to approx 1.7GB, which should be no problem for my PC.
    Why I want to use QList:
    Later in my program I'd like to use this List as container for my data. And I want to insert smaller lists the size of 4e6 elements and what I've read so far is, that the QList is better for inserting elements, is that true or false? If the later I could stick to QVector and forget about QList...

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved