Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    [SOLVED]qUncompress not enough memory

    General and Desktop
    3
    7
    5928
    Loading More Posts
    • 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
      Jake007 last edited by

      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 Reply Quote 0
      • M
        MuldeR last edited by

        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 Reply Quote 0
        • J
          Jake007 last edited by

          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 Reply Quote 0
          • T
            tobias.hunger last edited by

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

            1 Reply Last reply Reply Quote 0
            • J
              Jake007 last edited by

              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 Reply Quote 0
              • T
                tobias.hunger last edited by

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

                1 Reply Last reply Reply Quote 0
                • J
                  Jake007 last edited by

                  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 Reply Quote 0
                  • First post
                    Last post