How can I allocate a buffer contains different types of data (for MPI communication, for example)?

The easiest way is probably to put these into a struct and then communicate the struct. I am not sure whether

matters for performance. So before you make large changes to your code that might reduce readability, I recommend to benchmark whether these changes help at all.