saving a std::map instance into harddisk

Discussion in 'C++' started by ulaskaraoz@gmail.com, Jan 2, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Jan 2, 2007
    #2
    1. Advertising

  3. Lionel B Guest

    On Tue, 02 Jan 2007 13:29:51 -0800, 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-lite/serialization.html

    --
    Lionel B
    Lionel B, Jan 2, 2007
    #3
  4. John Guest

    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:
    > 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
    John, Jan 2, 2007
    #4
  5. 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.
    Gianni Mariani, Jan 2, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. angus

    how to access client harddisk?

    angus, Jun 15, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    727
    John Saunders
    Jun 15, 2004
  2. Peter Jansson
    Replies:
    5
    Views:
    6,255
    Ivan Vecerina
    Mar 17, 2005
  3. Replies:
    1
    Views:
    402
    red floyd
    Dec 21, 2008
  4. Thomas J. Gritzan
    Replies:
    6
    Views:
    993
    James Kanze
    Dec 22, 2008
  5. James Kanze
    Replies:
    0
    Views:
    1,975
    James Kanze
    Dec 21, 2008
Loading...

Share This Page