0

I am using QT4.8 with 32 bit Visual Studio 2010. I am trying to change some content of an XML File in a function.The function begins like that

QFile* myXmlFile;
QDomDocument myDom;
...
myDom.setContent(myXmlFile);

The Function works just fine when the xml file is smaller than 24 Mb. However, when I have file larger than that, the program crashes at the last line above. I found a similar question but it says the error occurs after 200Mb and the problem seems different.

I have 16 Gb of memory and you can hardly see the change in memory use, so it's probably not due to lack of memory.

When I use try catch block to see the problem, it says there is a bad allocation exception. It seems QDomDocument fails to allocate more than 24 MB, although there is far more free memory in the computer. I read Qt documents for QDomDocument but found no clue.

Is there a way I can let the program or that QDomDocument object to use more memory or do you think it is a different problem?

trincot
  • 317,000
  • 35
  • 244
  • 286
  • If the file is 24MB does not mean the RAM allocated will be 24MB it is likely to be much more, beside that your exe file could have a maximum HEAP limit, I believe you could change that from Visual Studio .. https://msdn.microsoft.com/en-us/library/f90ybzkh%28v=vs.120%29.aspx – Marco Nov 25 '15 at 11:56
  • If it crashes immediately or the alloc is much to large there would be no time or no occasion to see the memory use by QDomDocument. In addition: 32bit allows only 2GB by default ... see http://stackoverflow.com/q/639540/3021018 – Aaron Nov 25 '15 at 11:57
  • It does not crush immediately, actually it waits quite a long time at that line before it crushes. – tay stack Nov 25 '15 at 11:57
  • If your XML contains lots of small tags it would take more time to build up the dom document and will consume more memory. 'Quite a long time' sounds like that. – Aaron Nov 25 '15 at 11:58
  • @Aaron Yes, it has too many small tags. – tay stack Nov 25 '15 at 12:30
  • @Marco Thanks Marco, looks like Increasing heap did the trick. I said "looks like" because I have some other problems and program is not working now but this problem seems to disappear. – tay stack Nov 25 '15 at 12:33
  • I have turned the comment into an answer so those looking in future will know what to do, please accept the answer so people will know it works. – Marco Nov 25 '15 at 13:10
  • You may also vote up comments that pointed in the right direction to help people spotting the relevant infos. – Aaron Nov 25 '15 at 14:57
  • I can't. I guess I do not have enough rep for that. – tay stack Nov 26 '15 at 11:43

2 Answers2

0

If the XML file is 24MB on disk it does not mean the RAM allocated will be 24MB it is likely to be much more. Anyway a Windows EXE file could have a maximum HEAP limit, that can be increased from Visual Studio, see link..

Marco
  • 1,952
  • 1
  • 17
  • 23
0

I was wrong about Marco's advice solving the problem. Even though increasing heap may help in some cases, when you have too many small nodes, QDomDocument can became as large as 2GB and it's the limit for it. I guess the best way is to use XmlStream readers and writers.