boost::serialization, binary archive contents

Hi All, Im not sure if this the correct mailing list or not.. in fact im not sure if i'm even going about this the right way.. forums are so much easier.. Im using the boost::serialization library, im attempting to serialize an image file from the freeimage library. It is working beautifully if i serialize to a text archive however, binary archives fail to load with a "stream error" exception. With the freeimage library i can save the image to memory and then retrieve the pointer to the start memory address and also retrieve the size. With this information I attempt the following (NOTE, "io" is the freeimage memory stream (fipMemoryIO) which is returning the memory pointer and the size): void save(Archive & ar, const unsigned int version) const { BYTE * pData; DWORD dwSize; io.acquire(&pData1, &dwSize); ar & dwSize; boost::serialization::array<BYTE> ao = boost::serialization::make_array<BYTE>(pData, dwSize); ar & ao; } void load(Archive & ar, const unsigned int version) { BYTE * pData; DWORD dwSize; ar & dwSize; pData = new BYTE[dwSize]; boost::serialization::array<BYTE> ao = boost::serialization::make_array<BYTE>(pData, dwSize); ar & ao; // <----------- This throws an exception } The above throws the exception.. even though it succeeds with a text archive. What is even more frustrating is that if (when saving) the contents pData1 points to are changed, when loading there is no exception. (Obviously the bitmap would be corrupt but thats beside the point). void save(Archive & ar, const unsigned int version) const { BYTE * pData; DWORD dwSize; io.acquire(&pData1, &dwSize); ar & dwSize; memset(pData1, 0xAB, dwSize); // <--- Add this line an no exception is thrown. boost::serialization::array<BYTE> ao = boost::serialization::make_array<BYTE>(pData, dwSize); ar & ao; } I am at a loss. If i want to write x number of bytes it should write x number of bytes no matter what those bytes are.. I must be doing something wrong because this just doesnt make sense. The exception is always thrown in basic_binary_iprimitve.hpp if(scount != s) boost::serialization::throw_exception( archive_exception(archive_exception::stream_error) ); Regards, Dan

Am Wednesday 23 December 2009 02:22:09 schrieb Dan:
Hi All,
Im not sure if this the correct mailing list or not.. in fact im not sure if i'm even going about this the right way.. forums are so much easier..
there is a boost-users mailing list on the same site you joined this one. but I would like to see a message board on the boost website as well. noone is used to mailing lists anymore.
Im using the boost::serialization library, im attempting to serialize an image file from the freeimage library.
It is working beautifully if i serialize to a text archive however, binary archives fail to load with a "stream error" exception.
is your stream a std::ios::binary stream? see http://www.boost.org/doc/libs/1_41_0/libs/serialization/doc/special.html#bin...
boost::serialization::array<BYTE> ao = boost::serialization::make_array<BYTE>(pData, dwSize); ar & ao;
your code looks ok. you can replace this part with ar.load_binary(pData,dwSize). (this has nothing to do with the exception you're getting though, it's just easier to read.)

Thanks for both of your replys. Please excuse my late reply, work has finished for the year and the ISP at home is messing around (been without internet for over a month!). Im posting this from a internet cafe so my i may not be able to reply frequently. Yes i did insure that std::ios::binary was specified for the archive. I cant remeber if i posted this in my previous message (and am not sure how to check) however, I did more testing and managed to get a simple binary archive example to work for a particular image. Without changing the code, apart from making it load a different image, caused it to then throw the exception. I will try to post an example that shows the issue at some point. Other than the std::ios::binary is there any other differences required between the text and binary archives?
Am Wednesday 23 December 2009 02:22:09 schrieb Dan:
Hi All,
Im not sure if this the correct mailing list or not.. in fact im not sure if i'm even going about this the right way.. forums are so much easier..
there is a boost-users mailing list on the same site you joined this one. but I would like to see a message board on the boost website as well. noone is used to mailing lists anymore.
Im using the boost::serialization library, im attempting to serialize an image file from the freeimage library.
It is working beautifully if i serialize to a text archive however, binary archives fail to load with a "stream error" exception.
is your stream a std::ios::binary stream? see http://www.boost.org/doc/libs/1_41_0/libs/serialization/doc/special.html#bin...
boost::serialization::array<BYTE> ao = boost::serialization::make_array<BYTE>(pData, dwSize); ar & ao;
your code looks ok. you can replace this part with
ar.load_binary(pData,dwSize).
(this has nothing to do with the exception you're getting though, it's just easier to read.)
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Dan wrote:
Hi All,
Im not sure if this the correct mailing list or not.. in fact im not sure if i'm even going about this the right way.. forums are so much easier..
Im using the boost::serialization library, im attempting to serialize an image file from the freeimage library.
It is working beautifully if i serialize to a text archive however, binary archives fail to load with a "stream error" exception.
Double check that the stream is opened with ios::binary Robert Ramey
participants (3)
-
Dan
-
Robert Ramey
-
Stefan Strasser