[SOLVED]qUncompress not enough memory
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:
if(!f.open(QIODevice::WriteOnly | QIODevice::Text))
s.append(save().toString()); // save() returns QDomDocument
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.
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...
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 ;) .
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.
Because if I don't, I get an error:
@qUncompress: Z_DATA_ERROR: Input data is corrupted@
If I do save it as base64, I get again an error that there isn't enough memory.
tobias.hunger last edited by
Try doing a base64 encoding when saving or better yet: Change the file you write to binary.
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:
@qUncompress: Input data is corrupted@
@qUncompress: Z_DATA_ERROR: Input data is corrupted // Notice Z_DATA_ERROR@
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!