Re: [Boost-users] Serialization newbie needs help

Frank Birbacher wrote:
Frank is right. I don't quite know what Robert thought I was looking for, but it's pretty clear that his suggested code does not do what I want. (Nor does it compile!) To clarify: write_to_cbuffer() should serialize a my_class instance into a c-style char* buffer. It also needs to dynamically allocate storage for the buffer, set buf_p to point at the buffer, and set buf_sz to the size of the buffer. This is so that the legacy C code can then call write(fd, buf_p, buf_sz). read_from_cbuffer() does the opposite: it extracts a serialized instance of my_class from a char* buffer. I'll take a look at the boost::iostreams stuff to see if I can figure out how to make that work. Thanks for the tip, Frank. BTW, I don't think a push_back() is any faster for a deque than a vector -- it is push_front() that is faster for a deque. From the STL docs at SGI: "The main way in which deque differs from vector is that deque also supports constant time insertion and removal of elements at the beginning of the sequence". -- Dominick

Hi! Dominick Layfield schrieb:
I'll take a look at the boost::iostreams stuff to see if I can figure out how to make that work. Thanks for the tip, Frank.
See here for an array "Device": http://www.boost.org/libs/iostreams/doc/classes/array.html#array_source And here for the stream wrapper: http://www.boost.org/libs/iostreams/doc/index.html These two make an istream for reading your char buffer. See the tutorial at http://www.boost.org/libs/iostreams/doc/index.html for usage instructions.
Yes, the approximate complexity is the same, namely O(1) or "constant time". But the vector need to enlarge itself from time to time (althought this takes approximately constant time). A deque does not need to copy its contents to enlarge itself. You'd need to do some profiling to find out who's the winner. Frank
participants (2)
-
Dominick Layfield
-
Frank Birbacher