
Hi all, I'm trying to serialize an object to an array of uint8_t which is basically array of bytes. The source code that I have is ... vector<string> names; uint8_t data[60000]; // push_back 10 names ofstream ofs ( "names.txt" ) boost::archive::text_oarchive os ( ofs ); oa & names; ofs.close(); What I want to ask here is how I can avoid to create a file and fill the data array instead by using boost serialization? Any comments will be appreciated. best regards, -- Alexander Dong Back Kim

On Fri, Aug 8, 2008 at 1:28 PM, Alexander Dong Back Kim <alexdbkim@gmail.com> wrote:
What I want to ask here is how I can avoid to create a file and fill the data array instead by using boost serialization? Any comments will be appreciated.
Try using a stringbuf, then wrap it in an std::ostream, which you then use to initialize the archive: std::stringbuf buffer; std::ostream stream(&buffer); text_oarchive archive(stream); HTH -- Dean Michael C. Berris Software Engineer, Friendster, Inc.

Dean Michael Berris wrote:
On Fri, Aug 8, 2008 at 1:28 PM, Alexander Dong Back Kim <alexdbkim@gmail.com> wrote:
What I want to ask here is how I can avoid to create a file and fill the data array instead by using boost serialization? Any comments will be appreciated.
Try using a stringbuf, then wrap it in an std::ostream, which you then use to initialize the archive:
std::stringbuf buffer; std::ostream stream(&buffer); text_oarchive archive(stream);
HTH
Or std::ostringstream oss; text_oarchive archive(oss); or see the boost::iostreams library to provide a stream or stream_buffer that directly writes to a container or any other memory you provide. Jeff Flinn

On Fri, Aug 8, 2008 at 9:42 PM, Jeff Flinn <TriumphSprint2000@hotmail.com>wrote:
Dean Michael Berris wrote:
On Fri, Aug 8, 2008 at 1:28 PM, Alexander Dong Back Kim <alexdbkim@gmail.com> wrote:
What I want to ask here is how I can avoid to create a file and fill the data array instead by using boost serialization? Any comments will be appreciated.
Try using a stringbuf, then wrap it in an std::ostream, which you then use to initialize the archive:
std::stringbuf buffer; std::ostream stream(&buffer); text_oarchive archive(stream);
HTH
Or
std::ostringstream oss; text_oarchive archive(oss);
or see the boost::iostreams library to provide a stream or stream_buffer that directly writes to a container or any other memory you provide.
Jeff Flinn
Oh! This is alos really good suggestion! I will go and dig more on boost::iostreams library =) Thanks a lot. -- Alexander Dong Back Kim Australia +61 433 469 100 / Korea +82 10 6357 8840

On Fri, Aug 8, 2008 at 6:46 PM, Dean Michael Berris <mikhailberis@gmail.com>wrote:
On Fri, Aug 8, 2008 at 1:28 PM, Alexander Dong Back Kim <alexdbkim@gmail.com> wrote:
What I want to ask here is how I can avoid to create a file and fill the data array instead by using boost serialization? Any comments will be appreciated.
Try using a stringbuf, then wrap it in an std::ostream, which you then use to initialize the archive:
std::stringbuf buffer; std::ostream stream(&buffer); text_oarchive archive(stream);
HTH
-- Dean Michael C. Berris Software Engineer, Friendster, Inc.
Thanks for the hint! Since I was deal with byte array I couldn't think about using stringbuf. However, I realized that char array is byte array anyway so stringbuf can be used anyway so your suggestion is perfectly suit for my case. Thanks a lot =) -- Alexander Dong Back Kim Australia +61 433 469 100 / Korea +82 10 6357 8840
participants (3)
-
Alexander Dong Back Kim
-
Dean Michael Berris
-
Jeff Flinn