On Tue, Mar 3, 2009 at 8:22 AM, aepensky <apen...@gmail.com> wrote:
> I was reading through the code and I'm not sure I understand the
> thought behing the ZeroCopyInputStream implementations.
> It seems to me that if the underlying data source actually *is* a
> stream to begin with, "ZeroCopy" does not perform any fewer copies;
> using the copying adapter, it allocates an internal buffer, fills the
> internal buffer from the stream as needed, and then provides a
> ZeroCopy stream interface to that internal buffer. So, the amount of
> copying appears to be the same as if you read the stream into memory
> yourself and then called ParseFromArray.
> What am I missing?
You're missing nothing. ZeroCopyInputStream only provides advantages when
the data source is *not* a stream to begin with. If you already happen to
have your data in in-memory data structures, then ZeroCopyInputStream
provides an abstract way to read that data without copying any bytes.
It may also be possible to write a true ZeroCopyInputStream for OS-level
streams. For files you could do it easily using mmap(), or for general file
descriptors you might be able to do it with AIO. But I don't know of anyone
who has bothered to do this.
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to email@example.com
To unsubscribe from this group, send email to
For more options, visit this group at