Why waste your time figuring out an algorithm for storing things in a file? And why spend time debugging the code? Let the Boost library do it for you. Saving your data to your own custom-made file formats is easy with the help of the Boost serialization templates. Jeff Cogswell shows you how to save the data and read it back in with ease.
boost…I never could compile the damn thing in windows + VC 7.1
Object serialization… if you want dead data that cannot be easily shared with anything else.
Otherwise, applications need to utilize XML or a database to keep important data so that it can be used by other apps or even by loadable modules of the same system.
One day people will realize that “objects” were basically designed wrong from the get go. People keep wondering why so much stuff just doesn’t work right with objects… for those who are struggling… do not worry… the truth awaits… and it will set you free.
and what is the right way?
The boost serialization library supports XML archives.
Just a little FYI for those of you that have bought into the XML hype.
And what makes you believe it doesn’t support XML? It supports binary (in a very portable fashion) as well as XML. VC 7.1 shouldn’t have any major issues with boost serialization. I agree, the library doesn’t solve 100% of your possible serialization problems, but in numerous cases it just works fine.
However, serialized objects are still not a good way of dealing with most data storage needs.
Most of the time, there are massive issues with program version 1.1 vs. 1.0 when serialization is involved.
Coming up with good data formats is usually harder than building the application itself.
Data + algorithms = programs.
Computer people spend so little energy on the “data” side of things, it is pathetic.
@goldstein
However, serialized objects are still not a good way of dealing with most data storage needs.
Most of the time, there are massive issues with program version 1.1 vs. 1.0 when serialization is involved.
Coming up with good data formats is usually harder than building the application itself.
Data + algorithms = programs.
Computer people spend so little energy on the “data” side of things, it is pathetic.
Ah, but serialisation is great for short-term storage. For example, searisling objects during a temoprary web application session. That’s a great and perfectly valid use for serialisation.
also chechout the qt-lib, as a great c++ exstention lib.
it started as a crossplatform GUI lib but since qt4 there is a pure nonGUI part. it gives you very high level algorithims, portable code, very good documentation and comes with either a GPL or a commercial licence. it is available for unix (incl. linux), mac and windows.
just my 2ct.
_cies.
I’ve been wondering how to create files in my applications. I’ll keep this in mind if i ever need it. The article itself is sort of “meh”, but i never new this boost library existed before now, so that’s useful.
So how does that & operator work in this case? How come it can both Read and Write to the values?
Not really interesting OS news, is it? :
(and can’t believe they havent ‘solved’ generic filesaving sooner)
The performance of almost all “serialization” systems is very very slow. And when you “deserialize” your objects… like dry milk, when reconstituted, it doesn’t taste quite like milk.
Most apps are better off using a dedicated state manager that handles persistence.
So how does that & operator work in this case? How come it can both Read and Write to the values?
The & operator is really a method call on the archive object. Depending on whether you want to read or write, an input or output archive is passed to the serialize method. The right-hand side arguments (x and y) are passed as references.
“Most apps are better off using a dedicated state manager that handles persistence.”
If it handles persistence then it will, by definition, serialize or deserialize at some point. Whether you store in binary format, xml, or a database makes no difference. I also find it interesting that you advocate xml in one breath and complain about performance in another.
Please try to keep in mind that the article’s audience is C++ developers and that many of us have been doing what we do professionally for many years. If your going to post to such a group, you should at least come off like you have a real clue.
Rapsey : “boost…I never could compile the damn thing in windows + VC 7.1
”
Use GCC 3.4.2 or better…
Kochise
Thank you Nimble, I didn’t think about the two different Archive types (input/output) yet. I’m not that sharp today
> also checkout the qt-lib
This is a good option, yes.
Not really interesting OS news, is it?
Actually, some of us do find this kind of thing rather interesting.
It’s PROGRAMMING news. And guess how operating systemsget beyond the planning and design phase? Come on, I KNOW you can guess it!
Besides, reading from and saving to files is so danged universal that maybe it’s good to remind people how to do it. Novice or intermediate programmers especially need to know.
Not a bad article, anyway, and thanks to the others for mentioning QT4’s utility library, qt-lib. Mind you, I never took my XML medicine, but I confess myself fond of plaintext files and CSV’s when things needed to be human readable.
I also am slowly becoming a fan of “real” databases as well (slowly learning SQL, warts and all).
–JM
boost…I never could compile the damn thing in windows + VC 7.1
Did you try at all? Go to the jam go to tools/build/jam_src and run build.bat if you have problems check your paths. Once that is done copy the executables it creates (they will be in the directory (bin.ntx86 or your equiv)) to the root directory of your boost source then run bjam and sit back and wait. Would have to be one of the simplest build processes ever.
Oh and also I had linking issues with the multithreaded dll libs which switching to the multithreaded static libs solved. (For the record I didn’t put much effort into getting the dll libs working.)