Yes, use std::string. The only potential problem is if your messages are
very large -- allocating large contiguous blocks of memory (as std::string
does) could lead to memory fragmentation. But for small and medium-sized
messages, there's no reason not to use std::string as the buffer. Parsing
from an std::string (or a simple array -- they're essentially the same) is
(slightly) faster than parsing from any other data structure.
On Tue, Nov 24, 2009 at 9:07 AM, Evan Jones <ev...@mit.edu> wrote:
> Gilad Ben-Ami wrote:
> > Do you think that using std::iostream in the following scenario would
> > work / be a good choice?
> > 1. read message_length
> > 2. buffer message_length bytes into iostream variable.
> > 3. when all data is received, use IstreamInputStream to wrap the
> > iostream and have it parsed with ParseFromZeroCopyStream()
> If your application doesn't have a buffer already, I recommend using
> std::string. AFAIK, the C++ standard library doesn't provide anything
> more appropriate. It will do a good enough job, particularly if you
> re-use one std::string rather than allocating a new one for each message.
> The reason to use something more complicated is because lots of
> applications already have some sort of buffer, and you want to try and
> avoid extra copies.
> Evan Jones
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> For more options, visit this group at
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to
For more options, visit this group at