I had a a performance problem when using TinyXML to parse an xml file which contained a large (ca. 4MB) CDATA section.
The performance bottleneck was the continuous reallocation of the std::string class when adding another character to the value member variable.
At least in MS VC++ 6 the std::string object grows by a constant amount which is horrible if you read large blocks of data. Therefore I would suggest the following patch.
Wow - the MS VC6 STL implementation leaves a lot to be desired. Interesting information.
Effectively however, your patch overrides the STL memory allocation scheme, which isn't a good idea either. A safer fix might be:
#if (_MSC_VER == 1300 ) // or some such version #
...your allocation patch...
#endif
but I am trying as much as possible to stay out of the compiler version game. I think it is better, in the main distribution to live with non-critical compiler issues.
It's a great tip for people using that compiler however. Another approach is to switch to STLPort which works fine with VC6 and is an altogether better implementation of STL.
lee
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
I had a a performance problem when using TinyXML to parse an xml file which contained a large (ca. 4MB) CDATA section.
The performance bottleneck was the continuous reallocation of the std::string class when adding another character to the value member variable.
At least in MS VC++ 6 the std::string object grows by a constant amount which is horrible if you read large blocks of data. Therefore I would suggest the following patch.
Index: tinyxmlparser.cpp
--- tinyxmlparser.cpp (Revision 2750)
+++ tinyxmlparser.cpp (Arbeitskopie)
@@ -1459,6 +1459,8 @@
&& !StringEqual( p, endTag, false, encoding )
)
{
+ if (value.capacity()==value.length())
+ value.reserve(value.capacity()*2) ;
value += *p;
++p;
}
Wow - the MS VC6 STL implementation leaves a lot to be desired. Interesting information.
Effectively however, your patch overrides the STL memory allocation scheme, which isn't a good idea either. A safer fix might be:
#if (_MSC_VER == 1300 ) // or some such version #
...your allocation patch...
#endif
but I am trying as much as possible to stay out of the compiler version game. I think it is better, in the main distribution to live with non-critical compiler issues.
It's a great tip for people using that compiler however. Another approach is to switch to STLPort which works fine with VC6 and is an altogether better implementation of STL.
lee