I had assumed that protocol buffers are always read from/written to
in-memory data structures. Is there something else?
> because they can direct the parser/serializer directly
> at the memory rather than copying to/from separate buffers.
After I build up a protocol buffer, I need to call
SerializeToOstream/SerializeToString/etc., which performs a copy, right?
So where exactly do these fit in? Are they an intermediate buffer so
as to reduce SerializeTo* to what's basically a memcpy?
And would these have poor worst-case performance if the protocol buffer
is built up using a sequence of operations that is not amenable to
direct serialization? (E.g. insertions that cause subsequent bits to be
shifted.)
And when I use ParseFrom*, I can imagine a buffer-backed implementation,
but this would be unsafe (could be left with a dangling reference once
the backend is destroyed) - which, AFAIK, is not the case with protobufs.
--
Yang Zhang
http://www.mit.edu/~y_z/
Kenton Varda wrote:I had assumed that protocol buffers are always read from/written to in-memory data structures. Is there something else?
The ZeroCopyStream interfaces are the underlying abstract stream interfaces used by the protocol buffer I/O code. Messages are parsed from ZeroCopyInputStreams and written to ZeroCopyOutputStreams. These classes are particularly useful when reading from / writing to in-memory data structures
After I build up a protocol buffer, I need to call SerializeToOstream/SerializeToString/etc., which performs a copy, right?
because they can direct the parser/serializer directly at the memory rather than copying to/from separate buffers.
So where exactly do these fit in?
Are they an intermediate buffer so as to reduce SerializeTo* to what's basically a memcpy?
And would these have poor worst-case performance if the protocol buffer is built up using a sequence of operations that is not amenable to direct serialization? (E.g. insertions that cause subsequent bits to be shifted.)
And when I use ParseFrom*, I can imagine a buffer-backed implementation, but this would be unsafe (could be left with a dangling reference once the backend is destroyed) - which, AFAIK, is not the case with protobufs.