On Tue, Jan 4, 2011 at 9:38 PM, Kenton Varda <ken...@google.com> wrote:

> 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.
>

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?


>
> 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 proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>

-- 
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 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to