Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

std::vector capacity inconsistencies



  • Hello everyone,

    This is the first time I'm posting on this forum, so I hope I'll be clear enough and you can help me with this strange problem.

    I am using QT OpenGL on a Windows 10 64-bit to show pointcloud from a PLY file, that can have more than 8 million of points (each points contains the x, y, z coordinates, and the RGBA value). I can read the data from this type of file, and since I have to read more than one PLY file, I'm currently storing it in a vector of vector of float.

    The problem is that I have a bad_alloc error while reading the fourth file of 8 million points. To understand more what the problem really was, I have created a test project containing 28 line, in which I initialized a vector of float and I store the same float value in it.

    This is where the inconsistency is: on Windows 10, i can only initialized a vector of float with a max capacity of about 412 millions value, one more and I have a bad_alloc error. But after testing on Linux, I can push_back more than 1 billion floating value without any error whatsoever.

    My projects (the test one and the real one) are in release mode, and I am compiling with the c++14 configuration.

    Is there a restriction on Windows 10 that limit the number of data stored in a std::vector? If so, can I remove it, or at least raise it so that I can store more than 412 million floating value?

    Here's the .pro of the test project:

    QT += widgets core gui
    
    CONFIG += c++14
    
    QMAKE_CXXFLAGS -= -O2 -std=c++11 -std=gnu++11
    QMAKE_CXXFLAGS += -O2 -s -std=gnu++14
    QMAKE_LFLAGS -= -O1
    
    
    SOURCES += \
        main.cpp \
    

    And here's the main.cpp:

    #include <QtGui>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        Q_UNUSED(argc);
        Q_UNUSED(argv);
        vector<float> test(412174164);  //<-- Add one more and a bad_alloc error raise.
        qDebug() << "OK!";
        for(long long int i = 0; i < 1e8; ++i)
        {
            try
            {
                test[i] = 0.15753f;
            }
            catch (const std::bad_alloc&)
            {
                qDebug() << i;
                while(true)
                    1;
                return -1;
            }
        }
        qDebug() << "KO!";
    
    	return 0;
    }
    

    Thanks in advance for your help.


  • Moderators

    @KevLob said in std::vector capacity inconsistencies:

    I am using QT OpenGL on a Windows 10 64-bit

    Are you also building a 64-bit application? A 32-bit application in 64-bit Windows only has access to 2 GiB of RAM.

    vector<float> test(412174164);  //<-- Add one more and a bad_alloc error raise.
    

    This requires 1.5 GiB of contiguous memory. Do you have that amount of RAM available? Is your RAM fragmented?



  • @JKSH said in std::vector capacity inconsistencies:

    @KevLob said in std::vector capacity inconsistencies:

    I am using QT OpenGL on a Windows 10 64-bit

    Are you also building a 64-bit application? A 32-bit application in 64-bit Windows only has access to 2 GiB of RAM.

    Oh... I feel stupid now. I was using MinGW 32-bit to build the application. I have changed it to MinGW 64-bit and I can now store more than a billion value.

    Thank you.


Log in to reply