One thing odd about your example is opening the text archive stream with "ios::binary". Do you know for a fact that the archive was created this way?
Robert Ramey
"Javier Sanz" wrote in message news:119b5fdf0902160414l5211789ci86085b2dab71d7cd@mail.gmail.com...
Hello,
I'm getting problems creating a boost::archive::text_iarchive with boosts version 1.35.0 and Visual C++ Studio 2005 (Version 8). When I do so I get a std::bad_alloc exception. The code is as follows:
void Serialize::deserialize(std::
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
------------------------------------------------------------------------------
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users