I think this would be too complicated to integrate into the official C++ implementation. You could, however, write an alternative protobuf implementation that provides this.Note that with the official implementation, you can avoid malloc costs by reusing message objects. A message object never frees any memory until the top-level object is destroyed, so if you reuse the object to parse multiple messages, you can avoid a lot of allocation costs after the first message.
You might also experiment with tcmalloc (part of the Google perftools package) to see if it is faster than your system's memory allocator.
On Wed, Dec 29, 2010 at 10:21 PM, aristohuang <pmp...@gmail.com> wrote:
eg.
message A {
string a; when set_a(), memory of a in heap(new/malloc)
int b; when set_b(), memory of b in stack
};
if defines many composite sub-class objects, a lot of time cost in new/
malloc. are you think so? or have a good idear for this?
--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
Yes, I have run into this same issue, when I occasionally read in a
"huge" message. I think this is "by design." As Kenton noted: if you
re-use the message, it never has to free / reallocate memory. See the
"Optimization Tips" in this document:
http://code.google.com/apis/protocolbuffers/docs/cpptutorial.html
There is a ::SpaceUsed() method that can be helpful.
Evan
--
Evan Jones
http://evanjones.ca/
A while ago, a colleague had a "memory leak" reusing a PB message which contained a repeated field. If I'm not mistaken the problem was that pb_message::Clear() calls vector<something>::clear() and string::clear() which does not really release the memory allocated. I can't really tell for sure actually.@Kenton, does that make any sense? If yes, is there a way to avoid it?