On Oct 29, 2009, at 16:45 , jta23 wrote: > and send them like this: > > byte size = (byte)msg.getSerializedSize(); > outputStream.writeByte(size); > outputStream.write(msg.toByteArray());
You should do the following instead: 1. Create a CodedOutputStream wrapping your OutputStream. 2. Use CodedOutputStream.writeVarInt32 to write the size 3. use msg.writeTo() to write it. It will look something like: CodedOutputStream out = CodedOutputStream.newInstance(outputStream); for ( ... ) { out.writeVarInt32(msg.getSerializedSize()); msg.writeTo(out); } out.flush(); This should avoid a whole ton of extra allocations/deallocations that are being done by your current approach. If you try this, please let me know what the performance numbers look like. Evan -- Evan Jones http://evanjones.ca/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---