[ASIO / Serialization] How to avoid the copy?
Hello, Referring to the boost::asio "Serialization" example, and specifically to the file connection.hpp which handles serialization over sockets: http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/example/serializati... When new data is to be received, first the message header is read, which contains the number of bytes for the body. Storage must be allocated to receive the body, and is then passed into ::read as boost::asio::buffer. For the purpose of using Serialize, it must then be converted to an std::istream, (in the example above, istringstream). As shown in the example, this requires an extra copy to be held in memory for the std::string. What's the best route to avoid this copy? Thanks, Dan Eaton Software Developer Acceleware Corp. (TSX-V:AXE) www.acceleware.comhttp://www.acceleware.com/ Phone: +1.403.249.9099 Ext.295 Fax: +1.403.249.9881 Email: daniel.eaton@acceleware.commailto:daniel.eaton@acceleware.com Get superpowered! Acceleware gets your products to market faster, better and stronger! This e-mail may contain information that is privileged and confidential and subject to legal restrictions and penalties regarding its unauthorized disclosure or use. You are prohibited from copying, distributing or otherwise using this information if you are not the intended recipient. If you have received this e-mail in error, please notify us immediately by return e-mail and delete this e-mail and its attachments from your system. Thank you. (c) 2008 Acceleware, Inc. All Rights Reserved
I think you can avoid the copy using
boost::iostreams::streamboost::iostreams::array_source
instead of std::istringstream.
Take a look at boost::iostreams documentation for more information.
On Mon, May 25, 2009 at 11:53 AM, Dan Eaton
Hello,
Referring to the boost::asio "Serialization" example, and specifically to the file connection.hpp which handles serialization over sockets:
http://www.boost.org/doc/libs/1_37_0/doc/html/boost_asio/example/serializati...
When new data is to be received, first the message header is read, which contains the number of bytes for the body. Storage must be allocated to receive the body, and is then passed into ::read as boost::asio::buffer. For the purpose of using Serialize, it must then be converted to an std::istream, (in the example above, istringstream). As shown in the example, this requires an extra copy to be held in memory for the std::string.
What's the best route to avoid this copy?
Thanks,
*Dan Eaton *Software Developer *Acceleware Corp. **(TSX-V:AXE)* *www.acceleware.com*http://www.acceleware.com/ **
Phone: +1.403.249.9099 Ext.295 Fax: +1.403.249.9881 Email: daniel.eaton@acceleware.com
* *
*Get superpowered!** **Acceleware gets your products to market faster, better and stronger!** ***
* *
This e-mail may contain information that is privileged and confidential and subject to legal restrictions and penalties regarding its unauthorized disclosure or use. You are prohibited from copying, distributing or otherwise using this information if you are not the intended recipient. If you have received this e-mail in error, please notify us immediately by return e-mail and delete this e-mail and its attachments from your system. Thank you. © 2008 Acceleware, Inc. All Rights Reserved
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- []'s Andre Paim Lemos
you would likely have to invent a "asio_streambuf" if such a thing doesn't already
exist. This would retrieve data when necessary into a smaller buffer which
could then be used by any of the streams. (This would be similar to string_streambuf).
This would work fine for serialization and be useful in general. I'd be suprised
if asio doesn't already have it.
Robert Ramey
"Dan Eaton"
participants (3)
-
Andre Paim Lemos
-
Dan Eaton
-
Robert Ramey