I am using Boost.Asio, I want to improve my system by using Zero-copy sendmsg/Receive. Can I use Zero-copy sendmsg/Receive in Boost.Asio? Could you give me how to use them if I can use them?
Short answer, you can only if your in-memory representation is identical to the on-the-wire one.
See the answers here, which do an excellent job of describing how e.g. Cap'n Proto achieves this:
Also compare:
And on creating memory-mappable representations of advanced C++ data structures so that they can be mapped on-the-wire:
https://www.boost.org/doc/libs/1_72_0/doc/html/interprocess/managed_memory_segments.html#interprocess.managed_memory_segments.making_ipc_easy.managed_memory_segments_intro, specifically about basic_managed_heap_memory
and basic_managed_external_buffer
I have a gazillion examples on this site which show how to use such managed memory segments, but usually focused on managed_mapped_file
and managed_shared_memory
which have the exact same feature set, so you can use these with the previous managed heap segments in the same way: https://stackoverflow.com/search?q=user%3A85371+interprocess+allocator