ifstream &modelFile,
CoreModel &c)
{
try
{
boost::archive::text_iarchive ia(modelFile); // This line throws the exception (I've seen it with the debugger)
ia >> c;
}
catch (std::exception& ex)
{
// I catch the bad_alloc here
}
}
And this code si called this way:
...
for (...)
{
modelFile.open(model_name.c_str(), std::ios::binary);
if (modelFile.is_open() == false)
{
// ... We deal with the error but it does not get into here
}
CoreModel model;
Serialize::deserialize(modelFile, model);
....
}
With the debugger I have seen that the exception is thrown into the method text_iarchive_impl<Archive>::load.
The method basic_text_iprimitive::load is not setting the size of the
string and when the string resize is done the value is huge (is garbage
actually) and it throws the std::bad_alloc.
Digging into the mailing list I have seen a thread that explains the same problem:
http://lists.boost.org/boost-users/2006/03/18032.php
But the solution proposed there does not fit me (As far as I can see).
/Thanks
Francisco Javier Sanz Olviera