Boost serialization : Stream error exception

Discussion in 'C++' started by smith4894@excite.com, Aug 24, 2006.

  1. Guest

    { not sure you're aware of that but there are the newsgroups for all
    major operating systems. you might want to try asking in the forum
    'comp.os.linux.development.apps', since memory-mapped files are not
    a language-supported structure, they are platform-specific. -mod }

    I'm trying to use boost serialization to serialize/deserialize data to
    and from a mmap'd file. I have my own ostream/istream classes that
    essentially read/write bytes from a mmap'd file. The process works fine
    except on some rare occasions (With different objects/number of
    objects), in which case boost throws a "stream error" exception. Any
    ideas what could trigger this? A search of the Boost archives indicated
    other people had the same problem, where the solution was "use binary
    mode when you open the file"... but I'm not using a file on disk, I'm
    using a mmap'd file.

    The OS i'm using is Linux.


    Thanks for any suggestions...


    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
    , Aug 24, 2006
    #1
    1. Advertising

  2. kanze Guest

    wrote:
    > { not sure you're aware of that but there are the newsgroups for all
    > major operating systems. you might want to try asking in the forum
    > 'comp.os.linux.development.apps', since memory-mapped files are not
    > a language-supported structure, they are platform-specific. -mod }


    > I'm trying to use boost serialization to serialize/deserialize data to
    > and from a mmap'd file. I have my own ostream/istream classes that
    > essentially read/write bytes from a mmap'd file. The process works fine
    > except on some rare occasions (With different objects/number of
    > objects), in which case boost throws a "stream error" exception.


    On reading, or on writing? And what does "stream error" mean: I
    would expect that it refers to an error returned by the
    iostream, but it would be best to be sure---it could also refer
    to an error in the format of the input stream (unexpected EOF,
    etc.).

    > Any ideas what could trigger this? A search of the Boost
    > archives indicated other people had the same problem, where
    > the solution was "use binary mode when you open the file"...
    > but I'm not using a file on disk, I'm using a mmap'd file.


    The image must be binary, i.e. when you read, you must be
    guaranteed to see exactly the same bytes as when you wrote.

    Writing to a mmap'd file can be tricky. Basically, mmap (at
    least under Unix) presents a view of a fixed length file; if a
    write would extend the file, you have to take special actions.
    If you don't, it's entirely possible that when you reread the
    file, you loose a bit at the end. (It's also possible, of
    course, that you core dump on writing.)

    --
    James Kanze GABI Software
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
    kanze, Aug 24, 2006
    #2
    1. Advertising

  3. wrote:
    [...]
    > I'm trying to use boost serialization to serialize/deserialize data to
    > and from a mmap'd file. I have my own ostream/istream classes that
    > essentially read/write bytes from a mmap'd file. The process works fine
    > except on some rare occasions (With different objects/number of
    > objects), in which case boost throws a "stream error" exception. Any
    > ideas what could trigger this? A search of the Boost archives indicated
    > other people had the same problem, where the solution was "use binary
    > mode when you open the file"... but I'm not using a file on disk, I'm
    > using a mmap'd file.


    In my opinion you stand better chances of receiving help if you post to
    the Boost User mailing list:
    http://www.boost.org/more/mailing_lists.htm#users

    Cheers,
    Nicola Musatti


    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
    Nicola Musatti, Aug 24, 2006
    #3
    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. Replies:
    8
    Views:
    2,227
    deadsea
    Jan 2, 2005
  2. Replies:
    2
    Views:
    2,894
  3. Replies:
    3
    Views:
    1,011
  4. Dimitri Ognibene
    Replies:
    4
    Views:
    768
    Dimitri Ognibene
    Sep 2, 2006
  5. Ramunas Urbonas
    Replies:
    1
    Views:
    383
    Dino Chiesa [Microsoft]
    Jul 27, 2004
Loading...

Share This Page