Utilizing all Desktop memory for QImage objects



  • I'm running the following test and only get down to the third image before the images become zero. I get no errors or warnings. I still have plenty of memory left on my box. My Win7-64 bit box has 6GB. When I start my test it starts with 2.22 GB used and peaks around 3.10 GB. My Test Image is around 225 MB. Any Suggestion?

    Thanks

    Results:
    img1 size = QSize(5819, 20543)
    img2 size = QSize(5819, 20543)
    img3 size = QSize(0, 0)
    img4 size = QSize(0, 0)
    img5 size = QSize(0, 0)
    img6 size = QSize(0, 0)
    img7 size = QSize(0, 0)

    @
    void MainWindow::on_pushButton_clicked()
    {
    QScopedPointer<QImage> img1(new QImage("test.png"));
    qDebug()<<"img1 size = "<<img1->size();
    QScopedPointer<QImage> img2(new QImage("test.png"));
    qDebug()<<"img2 size = "<<img2->size();
    QScopedPointer<QImage> img3(new QImage("test.png"));
    qDebug()<<"img3 size = "<<img3->size();
    QScopedPointer<QImage> img4(new QImage("test.png"));
    qDebug()<<"img4 size = "<<img4->size();
    QScopedPointer<QImage> img5(new QImage("test.png"));
    qDebug()<<"img5 size = "<<img5->size();
    QScopedPointer<QImage> img6(new QImage("test.png"));
    qDebug()<<"img6 size = "<<img6->size();
    QScopedPointer<QImage> img7(new QImage("test.png"));
    qDebug()<<"img7 size = "<<img7->size();
    }
    @


  • Moderators

    Is your executable(not the OS) 32 or 64 bit? Processes have limits on available address space.
    Here's a detailed table: "Windows memory limits":http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778.aspx#memory_limits

    It doesn't matter how much RAM you physically have. Pages of memory can be stored on hard drive if your machine runs out of physical RAM.
    More important are the address space limits. In 64bit app you could theoretically allocate up to 8TB. For a 32 bit process this is about 2GB (up to 4GB with some hackery) even on 64bit Windows.



  • It's irrelevant what space the compressed PNG file occupies on disc: it must be uncompressed in memory in order to support drawing on a per-pixel basis. Assuming 32 bits are allocated for each pixel in your colour image then, at the very least, your 5819x20543 image occupies 478 million bytes. You don't get many of these in RAM before you bang up against the 2GB 32-bit process limit in Windows.



  • Thank you for your responses. It now make sense what is happening. I'm using mingw as the compiler and I see that mingw has a 64 bit compiler for Windows. Unless I overlooked something, I don't see that Qt has a 64 bit set up for Windows. What is the easiest way to create a 64bit Qt development environment?


  • Lifetime Qt Champion

    Hi,

    You have to either build Qt using mingw-64 or build Qt using visual studio's 64 bit console. And then point QtCreator to that new version and use it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.