saving a std::map instance into harddisk

U

ulaskaraoz

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
 
V

Victor Bazarov

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
 
J

John

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
 
G

Gianni Mariani

John said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top