473,385 Members | 1,780 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

saving a std::map instance into harddisk

Hi,
I have a std::map instance that I want to save into harddisk so that I
donot have to recompute it each time. The map itself is keyed by a
string and the values are pointers to other objects. Is it possible the
whole data structure so that it can be loaded later?
Thanks

Jan 2 '07 #1
4 3111
On Tue, 02 Jan 2007 13:29:51 -0800, ul********@gmail.com wrote:
Hi,
I have a std::map instance that I want to save into harddisk so that I
donot have to recompute it each time. The map itself is keyed by a
string and the values are pointers to other objects. Is it possible the
whole data structure so that it can be loaded later?
Yes - but it's by no means trivial. You want to read up on
"serialization":

http://www.parashift.com/c++-faq-lit...alization.html

--
Lionel B
Jan 2 '07 #2
ul********@gmail.com wrote:
I have a std::map instance that I want to save into harddisk so that I
donot have to recompute it each time. The map itself is keyed by a
string and the values are pointers to other objects. Is it possible
the whole data structure so that it can be loaded later?
Not really (or perhaps I don't understand the question). Pointers are
meaningless outside of the current running process, so saving their
values to file would not help. Saving objects behind those pointer
would be better, of course, but then you'd be duplicating them. Maybe
you could rethink your approach or have some kind of permanent "handle"
(number, ID, whatever) assigned to every object (uniquely of course)
and then save those along with the strings...

I don't see a C++ language problem here, though.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 2 '07 #3

Rebuilding takes O(nlogn)
Loading takes O(n) with a larger constant.

Even if you could store it on the hard drive, probably it will
take more time to load that map than to rebuild it!

My 2 cents,
--j

Victor Bazarov wrote:
ul********@gmail.com wrote:
I have a std::map instance that I want to save into harddisk so that I
donot have to recompute it each time. The map itself is keyed by a
string and the values are pointers to other objects. Is it possible
the whole data structure so that it can be loaded later?

Not really (or perhaps I don't understand the question). Pointers are
meaningless outside of the current running process, so saving their
values to file would not help. Saving objects behind those pointer
would be better, of course, but then you'd be duplicating them. Maybe
you could rethink your approach or have some kind of permanent "handle"
(number, ID, whatever) assigned to every object (uniquely of course)
and then save those along with the strings...

I don't see a C++ language problem here, though.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jan 2 '07 #4
John wrote:
Rebuilding takes O(nlogn)
Loading takes O(n) with a larger constant.

Even if you could store it on the hard drive, probably it will
take more time to load that map than to rebuild it!
AFAICT there is no interface for std::map that provides for
loading/unloading and maintaining/optimizing the internal structures
other than a "hint" iterator i.e.:

iterator insert(iterator hint, const value_type& x)

Seems like no information but the elements and the order needs to be
stored on disk to employ this.

I doubt that this will result in an O(N) insertion or any significant
optimization for that matter but I'm willing to be proved wrong.
Jan 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Antti Granqvist | last post by:
Hello! I have following object relations: Competition 1--* Category 1--* Course 1 | | * Course
8
by: Kin Pang | last post by:
Hi, I have a routine where I'm using a std::map from a pair of ints to double for caching evaluation results. The cache depth could be upto say 1000 in depth. However, my application needs to...
5
by: cppaddict | last post by:
Hi, I'm confused about what the comparison operator in a map template is: In particular, I want to know why something like the following doesn't work: bool pointCompare(POINT p1, POINT p2)...
14
by: Flzw | last post by:
Well I have a map like this : std::map <string, CObject> ObjectList; I have a function like this : CObject* NewObject( char* Name, CArg* Arg) { std::string key = Name; ObjectList =...
1
by: Saeed Amrollahi | last post by:
Dear All C++ Programmers Hello I am Saeed Amrollahi. I am a software engineer in Tehran Sewerage Company. I try to use std::map and map::find member function. I use Visual Studio .NET. my...
3
by: Dan Trowbridge | last post by:
Hi everyone, In my attempt to port code from VS 6.0 to VS.NET I had some code break along the way, mostly due to not adhereing closely to the C++ standard. This may be another instance but I...
2
by: Gernot Frisch | last post by:
Hi, I know I can give a std::map a sorting function in the c'tor. However, I would need to _change_ the sorting behaviour of an existing instance. How would I do that? Thank you, --
20
by: Dilip | last post by:
I understand the C++ standard does not talk about threading. My question here is directed more towards what happens when a STL container is used in a certain way. I'd appreciate any thoughts. I...
3
by: massysett | last post by:
I'm puzzled about part of the standard. 23.1 states that items stored in a container must be assignable. Therefore, the items in a map--that is, std::pair<const Key, valuemust be assignable....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.