How to use Zero-copy sendmsg/Receive in Boost.Asio [closed]

六月ゝ 毕业季﹏ 提交于 2021-01-28 11:21:46

问题


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?


回答1:


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:

  • Do cereal and Boost Serialization use zero-copy?

Also compare:

  • TCP Zero copy using boost

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



来源:https://stackoverflow.com/questions/60254180/how-to-use-zero-copy-sendmsg-receive-in-boost-asio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!