To optimize the performance of this version, we maintain the message buffer inside the C code. Instances of a C struct type (lightweight object) Buffer (differnt from the Java side Buffer class) is used for maintain message vector. This lightweight object stores a pointer to the message vectors and other information that is used for operation on the message vector: information like original capacity, current capacity, and current write and read position of vector.
Message elements of all data types other than Object are stored as C char  array. This architectural decision means actual communication takes place only with MPI_BYTE data type. Before sending, we extract char  array from the C object and store the total number of data bytes of the array into the Primary header (see section 5.3). This size information is used to make sure capacity of receive side vector is large enough to hold incoming data. For elements of Object type, the serialized data are stored into a Java byte  array. We can send this array by copying into the existing message vector if it has space to hold serialized data array, or by using separate send if the original message vector is not large enough.
In latter case there will be two different sends from the sender side. The receiver side will have to expect a second message.