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. [SOLVED]qUncompress not enough memory
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]qUncompress not enough memory

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 6.7k 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.
  • J Offline
    J Offline
    Jake007
    wrote on 1 Dec 2012, 14:49 last edited by
    #1

    Hi!

    I'm trying to compress XML string, save it, and then read it, uncompress it and load it.
    Everything works OK until uncompressing it ( I think, a problem could occur while saving).
    I get an error:
    @qUncompress: could not allocate enough memory to uncompress data@

    I'm using the folowing code:
    Save
    @void Project::onSave()
    {
    QFile f(savePath());

    if(!f.open(QIODevice::WriteOnly | QIODevice::Text))
    return;

    QByteArray s;
    s.append(save().toString()); // save() returns QDomDocument

    f.write(qCompress(s));

    f.close();
    }@

    Load
    @void Project::onLoad()
    {
    QFile f(savePath());

    if(!f.open(QIODevice::ReadOnly))
    qDebug() << "Couldn to open file";//return;

    QString data = qUncompress(f.readAll().toBase64());

    ...@

    Program uses 50 MB of memory, test plain XML file is ~4KB, compressed files is ~700B large and there is 4 GB of RAM free.


    Code is poetry

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on 1 Dec 2012, 15:14 last edited by
      #2

      How much "RAM" (physical memory) you have free doesn't matter much. Even if all RAM was used up, the OS can still fall back to the Page File before an allocation would fail. It is more likely that you run out of virtual address space for your process! Remember that a 32-Bit process, by default, has only 2 GB of address space available. So what you have to monitor is the "Virtual Size" of your application. An application can allocate up to 2 GB of memory and then run out of virtual address space (i.e. next allocation fails) without ever actually occupying any physical memory (RAM)! That's because memory gets allocated in the virtual address space. But the underlying OS doesn't assign "real" memory pages to that (virtual) memory until it's actually accessed.

      So quite possible something else in your application leaks a lot of memory and then qUncompress() fails...

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jake007
        wrote on 1 Dec 2012, 15:43 last edited by
        #3

        Currently there isn't any memory leak in a program. Most of all calls is commented out for debugging. Program is at 50 MB stable.
        So that sill leaves him ~1.95 GB of RAM to process 700 B compressed file and converts it to 4 KB large string.
        I'd say it should be more than enough ;) .


        Code is poetry

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on 1 Dec 2012, 15:50 last edited by
          #4

          Why is there a toBase64() in line 8 of the load routine? You don't encode to base64 while saving.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jake007
            wrote on 1 Dec 2012, 16:05 last edited by
            #5

            Because if I don't, I get an error:
            @qUncompress: Z_DATA_ERROR: Input data is corrupted@

            EDIT:
            If I do save it as base64, I get again an error that there isn't enough memory.


            Code is poetry

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on 1 Dec 2012, 16:07 last edited by
              #6

              Try doing a base64 encoding when saving or better yet: Change the file you write to binary.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                Jake007
                wrote on 1 Dec 2012, 16:22 last edited by
                #7

                I removed QIODevice::Text when saving. I assume that it's binary by default, as there is no binary flag.
                I added toBase64 when saving and fromBase64 when reading.
                I still get an error that data is corrupted.

                When I remove conversion to/from base64 on both sides, it's the same error: input data is corrupted.

                The only difference is with and without base64 is:
                With base64:
                @qUncompress: Input data is corrupted@

                Without base64:
                @qUncompress: Z_DATA_ERROR: Input data is corrupted // Notice Z_DATA_ERROR@

                EDIT
                After recompiling entire project, started to work. There are no Text mode flags while reading, saving, and there is no conversion to base64.
                Marked as Solved.

                Thanks for the help!

                Regards,
                Jake


                Code is poetry

                1 Reply Last reply
                0

                1/7

                1 Dec 2012, 14:49

                • Login

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