I want to send raw int
s with boost.asio compatibly with any CPU architecture. Usually, I would convert int
s to strings, but I may be able to get better performance by skipping the int
/ascii conversion. I don't know what boost.asio already does under the hood such as using htonl
. The documentation doesn't say and there is no way to test this code on my own PC.
Here are several methods I have to send an array of int
s over the network:
- Store the
int
s in an array ofint32_t
. Usehtonl
andntohl
to get correct endian-ness. Ifint32_t
is not supported on the target machine, handle that withint_fast32_t
and extra work. - Use boost.serialization. The only example I can find is from pre-C++11 times (see section on serialization), so I don't know if boost.serialization and boost.asio should still be used in this way. Also, as boost.serialization is a black box, it isn't clear what the performance overhead of using this library is.
- Convert each int to the ascii representation.
I think (1) is the "correct" alternative to non-ascii conversion. Can boost.asio or boost.serialization perform any of the steps of (1) for me? If not, what is the current recommended way to send int
s with boost.asio?