469,626 Members | 1,529 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Writing an STL map to disk.

Hey there :)

I was once told that the STL classes had member functions to write their
data to disk and to restore that data. Searching google (and why are there
no "stl" or "map" manpages?), it seems like someone was pulling my leg,
because I really can't find anything about it.

So, was I misinformed? Or perhaps this person was talking about some other
classes you could use to do such a thing?

TIA,
Daniel :)
--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #1
6 5404
DanielEKFA wrote:
I was once told that the STL classes had member functions to write their
data to disk and to restore that data. Searching google (and why are there
no "stl" or "map" manpages?), it seems like someone was pulling my leg,
because I really can't find anything about it.


Prepare yourself for a shock, but not everything has a manpage. My Panasonic
TV doesn't, for example.

These hits look promising:

http://www.google.com/search?q=seria...%3Aboost%2Eorg

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #2
DanielEKFA wrote:
I was once told that the STL classes had member functions to write their data to disk and to restore that data.


No, you probably mean RogueWave classes.
But you can write a for-loop with fwrite() for serialization and a
for-loop with fread() for deserialization. :-)

::A::

Jul 23 '05 #3
Phlip wrote:
DanielEKFA wrote:
I was once told that the STL classes had member functions to write their
data to disk and to restore that data. Searching google (and why are
there no "stl" or "map" manpages?), it seems like someone was pulling my
leg, because I really can't find anything about it.
Prepare yourself for a shock, but not everything has a manpage. My
Panasonic TV doesn't, for example.


....yet ;)
These hits look promising:

http://www.google.com/search?q=seria...%3Aboost%2Eorg


Didn't know the term serialization (other than in a scheduling context),
will have a look, thanks :)

--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #4
Abecedarian wrote:

No, you probably mean RogueWave classes.
Could be, not sure... Checking it out.
But you can write a for-loop with fwrite() for serialization and a
for-loop with fread() for deserialization. :-)

This serialization term in this context is new to me... Is this like
balancing a binary tree by writing it in pre-order to a file and then
restore it be reading back the data from the file?
::A::


Cheers,
Daniel :)

--
Why do cats jump out of windows? Because there's love out there!
Jul 23 '05 #5
DanielEKFA wrote:
But you can write a for-loop with fwrite() for serialization and a
for-loop with fread() for deserialization. :-)
This serialization term in this context is new to me...
"Serialize" is the generic term for turning structured data into a
restructured stream.

Then, the first big question is whether the stream should use text or binary
encoding. Prefer text until you find a hard reason to use binary.

So serializing to XML is safer and more humane than writing raw data with
fwrite(). That will narrow your options to read the file.

Next, your data needs structure. Text formats like XML provide that with ><
marks, linefeeds, etc. Binary formats often encode the length of each field
before the field.

One impressive binary format out there is simply a GZip of an XML file. The
only requirement was small file size, and if both your GZip and XML
libraries can stream, then you can read efficiently.
Is this like
balancing a binary tree by writing it in pre-order to a file and then
restore it be reading back the data from the file?


Like. But that changed the raw structure on the way. (And to balance, you
should either use a std::map with the balancing act built-in, or you should
write the tree straight into another tree, or you can skip the problem and
not prematurely optimize.)

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #6
DanielEKFA wrote:
Abecedarian wrote:
But you can write a for-loop with fwrite() for serialization and a
for-loop with fread() for deserialization. :-)


This serialization term in this context is new to me... Is this like
balancing a binary tree by writing it in pre-order to a file and then
restore it be reading back the data from the file?


std::map has iterators. You can just write in 'key=value' style
(similar to Windows INI files) to the file.

::A::

Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

48 posts views Thread by Joseph | last post: by
8 posts views Thread by Lu | last post: by
3 posts views Thread by ishekar | last post: by
16 posts views Thread by Ali | last post: by
12 posts views Thread by Chris Springer | last post: by
16 posts views Thread by Claudio Grondi | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.