Reusing proto object in a loop instead of creating new one each time

1,641 views
Skip to first unread message

Prakash Rao

unread,
Aug 20, 2010, 10:19:56 AM8/20/10
to Protocol Buffers, prakash...@gmail.com, prakash_rao...@hotmail.com
Hi,
Is it possible to re-use proto object while sending list of proto
objects instead of building a new proto object each time? Currently
i'm building a new proto object and it is put in a proto list & return
it to the client. Is it possible to re-use the proto object as stated
below?

// Create proto object (the same proto object is going to be used in
the while loop)
while loop {
// populate proto object
// wirte proto object to coded output stream
// clear proto object
}

flush coded outputstream

I'm trying to do this and it says you can't clear proto object once
it's already built. If this is possible, is there any performance
overhead with this approach (memory wise we might save something as we
are reusing proto object but clear API may add performance overhead).

Regards,
Prakash

Jason Hsueh

unread,
Aug 20, 2010, 3:14:46 PM8/20/10
to Prakash Rao, Protocol Buffers, prakash_rao...@hotmail.com
This has come up before on the list, for instance http://groups.google.com/group/protobuf/browse_thread/thread/6f4812e30a63b88a and http://groups.google.com/group/protobuf/browse_thread/thread/368f5b0518775a9d


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


Prakash Rao

unread,
Aug 21, 2010, 12:17:51 PM8/21/10
to Protocol Buffers
Thanks for your response. I thought of reusing proto messages in loops
but it is not supported for a good reason.

Regards,
Prakash

On Aug 21, 12:14 am, Jason Hsueh <jas...@google.com> wrote:
> This has come up before on the list, for instancehttp://groups.google.com/group/protobuf/browse_thread/thread/6f4812e3...http://groups.google.com/group/protobuf/browse_thread/thread/368f5b05...
> > protobuf+u...@googlegroups.com<protobuf%2Bunsubscribe@googlegroups.c­om>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/protobuf?hl=en.- Hide quoted text -
>
> - Show quoted text -

Michael Edgar

unread,
Aug 22, 2010, 1:04:01 PM8/22/10
to Protocol Buffers
It's worth noting that this is supported (and commonly done) with the C
++ API. But yeah - you're out of luck with Java.

On Aug 21, 12:17 pm, Prakash Rao <prakashrao1...@gmail.com> wrote:
> Thanks for your response. I thought of reusing proto messages in loops
> but it is not supported for a good reason.
>
> Regards,
> Prakash
>
> On Aug 21, 12:14 am, Jason Hsueh <jas...@google.com> wrote:
>
>
>
> > This has come up before on the list, for instancehttp://groups.google.com/group/protobuf/browse_thread/thread/6f4812e3......
> > > protobuf+u...@googlegroups.com<protobuf%2Bunsubscr...@googlegroups.c­om>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/protobuf?hl=en.-Hide quoted text -
Reply all
Reply to author
Forward
0 new messages