On Thu, Jul 23, 2009 at 12:32 AM, alopecoid <alopec...@gmail.com> wrote:

>
> Hi,
>
> I haven't actually used the Java protobuf API, but it seems to me from
> the quick occasional glance that this isn't entirely true. I mean,
> specifically in response to the code snippet posted in the original
> message, I would possibly:
>
> 1. Reuse the Builder object by calling its clear() method. This would
> save from the need to create a new Builder object for each iteration
> of the outermost loop.


You can't continue to use a Builder after calling build().  Even if we made
it so you could, it would be building an entirely new object, not reusing
the old one.  We can't make it reuse the old one because that would break
the immutability guarantee of message objects.

Reusing the actual builder object is not that useful since it's only a very
small object containing a pointer to a message object.


> 2. Iterate over the repeated field using the get*Count() and get*
> (index) methods instead of the get*List() method. I'm not sure if this
> would save anything, but depending on how things are implemented in
> the generated code, this could save from allocating a new List object.


Won't save anything; we still need a list object internally.

But seriously, object allocation with a modern generational garbage
collector is extremely cheap, especially for objects that don't stick around
very long.  So I don't think there's much to gain here.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to protobuf@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