There is an overhead in creating string object from the message.
It is more faster to obtain direct pointer to the data and length of
it.
inline bool has_name() const;
inline void clear_name();
static const int kNameFieldNumber = 1;
inline void set_name(const ::std::string value);
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
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 =