Reputation: 51
I have around 30 XML files, which my C++ process (at run time) should parse and make some installation.
I felt, instead of using XML at runtime, why can't I write a script which will encode the XML files into my own structure and generate a C++ program which should be compiled and built?
What I mean is, my script should populate the encoded structure as a variable assignment in C++ program.
Something like
class generatedCode
{
private:
unsigned char = ox11, ox22....
};
Then my C++ process will decode this and do installation instead of XML parsing.
My whole intention is the bring all the XML info by some means into C++ process memory.
Can someone please suggest, is this a good way? Do suggest any other ways of doing it?
Upvotes: 2
Views: 328
Reputation: 49920
Maybe I'm not interpreting your proposal correctly, but it sounds like you are starting with XML files, which describe how some installation process needs to be done. And you want to avoid parsing the xml by translating it into C++ code which can be compiled to do the installation.
If this "installation" is to be executed repeatedly, then this optimization you suggest might be worthwhile. But you aren't avoiding parsing the XML -- you need to parse it in order to translate them into your C++ program(s)! So your savings are in avoiding re-parsing the XML for each run, at the cost of having extra files (the executables) as well as having to re-build them whenever the XML changes.
Of course. if I'm misunderstanding the situation, as Roseanne Roseannadanna would say, "never mind" :)
Upvotes: 0
Reputation: 1
You could indeed "compile" (i.e. transform) these XML files into a more compact representation, and you might even generate a huge array to represent it in C++ code.
Perhaps a simpler solution could be to transform these XML files into your internal representation, and to use some fast memory projection mechanism (like mmap on Linux) to access it.
But you did not explain what these XML files represent and how do you want to use them later inside your application.
Upvotes: 1