When writing a sequence of MessageBuffers to MessageBufferOutput, we have a room to reduce the number of memory allocation by knowing the total size of MessageBuffers. But the current MessagePacker always reuses the pre-allocated MessageBuffer, so we cannot perform such an optimization.
By default, reusing the MessageBuffer as in the current implementation is OK. But we should make the interface of MessageBufferOutput more extensible to allow future optimization in memory allocation.
When writing a sequence of MessageBuffers to MessageBufferOutput, we have a room to reduce the number of memory allocation by knowing the total size of MessageBuffers. But the current MessagePacker always reuses the pre-allocated MessageBuffer, so we cannot perform such an optimization.
By default, reusing the MessageBuffer as in the current implementation is OK. But we should make the interface of MessageBufferOutput more extensible to allow future optimization in memory allocation.