472,331 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

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 5531
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and...
8
by: Lu | last post by:
Hi there, I got a program to write data to a randomly accessed file (the program moves file pointer to a certain position of the file according...
5
by: Ben Jeurissen | last post by:
Hello, I have to deal with the following issue in C++: Two threads are started from the main thread, both capturing images from a different...
3
by: ishekar | last post by:
Hi, I have an application where i want to write data to a file, the data is being sent from an external source. I know the total size of the data...
2
by: Jeevan | last post by:
Hi, I have an array of data (which I am getting from a socket connection). I am working on a program which acts on this data but the program is...
16
by: Ali | last post by:
Hi I want to write (or read) to a stream, but the data is not byte array I converted the data to byte array manually, but it is very slow,...
12
by: Chris Springer | last post by:
I'd like to get some feedback on the issue of storing data out to disk and where to store it. I've never been in a production environment in...
12
by: romayankin | last post by:
I plan to write site on a few language. For this reason I'm trying to find the most convenient way to output strings depending on their unique ID....
16
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte...
10
by: eastcoastguyz | last post by:
(I've not done C prorgamming in such a long time, I have forgotten how to do this.) I'm writing a program, where it fopens a file with "a+", and...
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.