Re: [protobuf] Is there a way to pass C string without triggering construction of string object in C++?

2010-01-07 Thread Evan Jones
On Jan 7, 2010, at 17:41 , Vlad wrote: inline const ::std::string& name() const; //problem here need creation of string -> very slow! This doesn't create a string, it just returns a reference to the string already in the protocol buffer object. If you do: const char* c_string = protobuff

Re: [protobuf] Is there a way to pass C string without triggering construction of string object in C++?

2010-01-07 Thread Kenton Varda
Protobuf messages store strings in std::string objects. Sorry, there's no way around that. The problem with direct pointers is that you have ownership issues -- what if the data pointed to is modified or free()d while the message still exists? Making a defensive copy is not that expensive and av