Comments (10)
This is the drawback of the memory managed approach, definitely.
Check out "ShallowClone". It copies a node, but not the nodes children, and is the main tool for the job. (There is example code in xmltest.cpp). For copying a full document, you'll need a recursive walk, and visit() seems like a reasonable choice although i haven't tried it.
Implementing "DeepClone" in the API is the right way, but I haven't implemented it yet.
from tinyxml2.
From my investigation it seems like the major memory problem in Tiny1 arises from the constant string reserve calls as xml is parsed into TiXmlString. It seems like pooling the strings in a string memory allocator would cleanup the allocations and still let the nodes be dynamically allocated? As it is I'm finding it tough to work out how to use Tiny2 when the code I am porting "picks" sub-trees out of an existing doc to create a new doc.
from tinyxml2.
Yeah, it's involved. The strings should be put in at least a per-document string pool. That's not required for a recursive copy, but certainly is in the spirit of things. But we could start with a recursive copy first and then go from there.
from tinyxml2.
For what its worth I modified TinyXML1 locally to support allocator 'hooks' such as:
TIXML_EXTERNFUNC( void , AllocHook )( size_t in_size );
then modified the tinystr.h function to call these hooks instead of directly allocating int arrays - ie...
size_t bytesToAllocate = intsNeeded * sizeof(int);
rep = reinterpret_cast<Rep_>(TinyXML::AllocHook(bytesToAllocate));
instead of:
rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
then I fed these allocations into a very fast fixed storage allocator.
In my tests this speeds up XML parsing by 3.5 times (I loaded 40 odd big xml files previously in 50seconds and now in 18 seconds).
If the lib can support the user settting up an external allocator as per above that will be helpful to others I bet... although its easy to modify since all the code is there. ;).
from tinyxml2.
Yeah, the main performance gain with TinyXML-2 is the memory management. Putting a better system into TinyXML-1 I'm sure helps there as well. But TinyXML-2 doesn't use statics or globals, which also helps with the threading model. I wanted to be sure that multiple XMLDocuments could be used simultaneously on multiple threads without locks. But to be clear: a given TinyXML-2 XMLDocument can only be used on a single thread.
from tinyxml2.
The deepCloning function would be greatly appreciated !
Does anyone have already a working visitor sample to do the same job ?
from tinyxml2.
+1 for DeepClone!
from tinyxml2.
+another one for DeepClone, this functionality shouldn't have been lost from the upgrade.
from tinyxml2.
Please see PR #558 (awaiting feedback until June 4th 2017)
from tinyxml2.
PR #558 merged.
from tinyxml2.
Related Issues (20)
- hello, i'm replacing your "placement new" with my old new, can you tell me if the code is safe? HOT 1
- LFS64 removal on musl-1.2.4
- Question: parsing a xml string back into an XMLDocument HOT 1
- CMake targets are not exported? HOT 1
- CMake install question HOT 2
- Converting CString to UTF-8 for saving to TinyXML2 HOT 1
- Problems occur when building a project
- XMLPrinter printer( fp ) not recognised on arduino ide compiler HOT 2
- Why return XML_ ERROR_ PARSING? HOT 2
- Documentation error? HOT 2
- Turkish Characters Support HOT 1
- When will tinyxml release a new version? HOT 1
- Assessment of the difficulty in porting CPU architecture for tinyXML2 HOT 1
- Support for char8_t and std::u8string HOT 2
- Using IntText(); HOT 1
- FirstChildElement and namespace prefixes.
- Bug with XMLElement::Attribute - it returns 0 instead of "value" if it can't find the attribute -
- Is the Doxygen tagfile published anywhere?
- v10: MinGW DLL build behavior change
- porty guide from tinyxml1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinyxml2.