Boost logo

Boost Users :

Subject: [Boost-users] boost.serialization throwing bad_alloc
From: James Vanns (james.vanns_at_[hidden])
Date: 2008-09-22 11:16:14


When using a stringstream in binary mode along with the non-portable binary archive occasionally I see the serialization code throw bad_alloc when reconstructing an object. It appears to be when trying to serialize a derived stl map. We derive from std::map in our project to add a few more convenience methods and a simpler interface and I then added the following code to serialize this newly derived type:

template<class Archive>
void
serialize(Archive &p_archiver,
foobar::ResourceMap &p_map,
const unsigned int version)
{
   p_archiver & base_object<map<foobar::ResourceMap::key_type,
                                foobar::ResourceMap::mapped_type> >(p_map);
}

I assume that is OK? It appears to work most of the time. Could it be that when that map is empty it encounters odd behaviour?

I pass, to the archive constructor, the no_header flag - is this a problem? I haven't tried the text archivers yet. This is with Boost version 1.35 on an x86-64 Linux installation (gcc 4.1.2) . I get the same behaviour with and without optimisation (-O0 -g3 and -g0 -Os) and with an unlimited stack size and a limit of ~10M.

Has anyone else seen similar behaviour. Using a hash function (SHA1) I can see that the same bytes that make up these messages (in our protocol classes are serialized in the payload of messages) are sent to and from the peers so I am pretty sure (though not 100% yet) it isn't due to any corrupt or incorrect data in the underlying stringstreams (the string streams are essentially made up of the message payload) themselves.

Regards,

Jim Vanns

-- 
James Vanns
Systems Programmer
Framestore CFC Ltd.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net