Jump to content
  • Advertisement
Sign in to follow this  
paic

xml and binary values

This topic is 3785 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I use xml as the general file format in my project, but I'd like to be able to handle binary values. I know we can't write binary values in an xml file, but I I've read that you can encode binary values into ascii ones, and vice versa. Problem is : I need to know how fast it to convert binary values into ascii ones, and roughly how does the algorithms work :) If any of you has detail / links / whatever could help me on the subject ... Thx in advance, have a nice day !

Share this post


Link to post
Share on other sites
Advertisement
Ok, thx, that answers the part about "how does the algorithms work" but my other question (and the one I'm most interested in knowing the answer :)) is : "is it fast ?"
I know "fast" doesn't mean anything. But imagine a game with hundreds of MBytes of resources to load. Is it reasonable to read my CDATA sections and then convert to binary ? Or will I end with 5 minutes of loading ?

Thx again for the answers :)

Share this post


Link to post
Share on other sites
Because of speed concerns, it's rare to see XML used in a production game as a resource file format. More commonly, XML is used as an editable version of the resources, and is compiled into a custom format during the binary build process.

Share this post


Link to post
Share on other sites
Quote:
Original post by paic
Ok, thx, that answers the part about "how does the algorithms work" but my other question (and the one I'm most interested in knowing the answer :)) is : "is it fast ?"
I know "fast" doesn't mean anything. But imagine a game with hundreds of MBytes of resources to load. Is it reasonable to read my CDATA sections and then convert to binary ? Or will I end with 5 minutes of loading ?

Thx again for the answers :)


If you have data, then you store it in XML in semantically useful manner - as human-readable nodes.

You can, for example, store model as XML nodes. <model><point x="1.0" y="2.0" texture="some_texture.png"/></model>. But store some_texture.png as a file. There is no benefit to be gained from putting BLOBs into XML.

Quote:
but I'd like to be able to handle binary values


XML is completely binary. Computers don't handle analogue value.

Quote:
Is it reasonable to read my CDATA sections and then convert to binary ? Or will I end with 5 minutes of loading ?


Fairly well written in-place zero-copy serialization is only about 4 times slower than memcpy.

But what kind of data do you want to store? What are the contents? What do you want to do with them?

Share this post


Link to post
Share on other sites
Just want to store vertex and index buffer content. I could store the content just like you said (human readable xml element) but that'd be awfully slow to load my scenes.

I already thought about storing the binary content (saved and loaded with a simple fwrite / fread) in another file, and simply write its filename in the xml, but I don't really like the idea of having 2 seperate files for one resource...

So, if the option of converting binary data to ascii content and vice versa is fast enough to load 100s of MBytes without the user falling asleep, I'd use this method. That's why I asked :)

Share this post


Link to post
Share on other sites
Quote:
Original post by paic
I already thought about storing the binary content (saved and loaded with a simple fwrite / fread) in another file, and simply write its filename in the xml, but I don't really like the idea of having 2 seperate files for one resource...

I use this method. Having two files isn't really an issue if you're generating them both as a build step from a single input file (eg. the original model file).

Then again, model data is sufficiently low-level that a custom binary file format also makes sense. I tend to stick to using xml for higher level metadata rather than large chunks best stored in it's original binary form.

Share this post


Link to post
Share on other sites
Ok, I just have one last question, more related to file formats :)

What you suggest is, if I understood correctly : Use an ascii format, easily readable / editable with the scene editor (or whatever is used to create the scene) and then, when the scene is fine, export everything (or maybe only stuff that require it) to another custom binary format ??

Seems fine to me ... except you have 2 loading methods to maintain ...

Thx for the inputs, it helped me a lot :)

Share this post


Link to post
Share on other sites
The benefits of having both a fast format and an easy to edit format may outweigh the costs of maintaining 2 readers/writers. Maintenance is minimal though - once you've worked out how to effectively read and write your basic types, and a few custom types specific to your application, there's typically nothing more to do, and you can write an object out to either format from then on.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!