Code Monkey home page Code Monkey logo

Comments (7)

leethomason avatar leethomason commented on July 17, 2024 1

The XMLDocument uses a significant amount of memory, and if it is copied, that means a deep copy of all that memory. In the likely case the compiler needs a temporary, then that memory gets copied twice. The copy and assignment operators are private for the reason that you almost certainly don't intend to move that much memory around.

If the cases you do, there is an open issue for "deep copy", but that's not in the code yet.

For now you need allocate the XMLDocument on the heap and return a pointer.

from tinyxml2.

aristotle0x01 avatar aristotle0x01 commented on July 17, 2024

from XMLDocument class definition, u can see that its copy constructor is private, but it needs copy constructor when returning XMLDocument, this is why u get an error.

from tinyxml2.

mclark4386 avatar mclark4386 commented on July 17, 2024

so the only way to pass the document around is via pointer/reference? is there any reason for it to not have a copy/move constructor? I'm just not sure I understand the logic here. Thanks so much for the info!

from tinyxml2.

aristotle0x01 avatar aristotle0x01 commented on July 17, 2024

"
XMLDocument( const XMLDocument& ); // not supported
void operator=( const XMLDocument& ); // not supported
"
above is from XMLDocument class definition, i do not know why. but it is intentionally not supported.

besides, consider not pass the document around if possible

from tinyxml2.

mclark4386 avatar mclark4386 commented on July 17, 2024

Thanks for closing this. What about having a move constructor compiled in if the compiler supports it? I can work on this, but I would rather not work on it and then it to be for nothing. I could just redesign my code. I see what you mean now though. I didn't think about the fact that it was all getting loaded into memory and then copying all of that memory. I probably need to redesign that code anyways, it's about 4 years old now and haven't we all learned a lot since then lol. Thanks for the response and explanation! Let me know if you want me make the move constructor^^

from tinyxml2.

leethomason avatar leethomason commented on July 17, 2024

The move constructor is an interesting suggestion. "if the compiler supports" is a frustrating issue, as well. Not yet. But I'll think about it. Thanks for the offer!

"haven't we all learned a lot since then" I hear you. Pretty much sums up why I wrote v2 of the library.

from tinyxml2.

jgoebec avatar jgoebec commented on July 17, 2024

I think move construct / assign would be appropriate at this point for a majority of projects out there.

from tinyxml2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.