1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>buffer_copy</title> 5<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../boost_asio.html" title="Boost.Asio"> 8<link rel="up" href="../reference.html" title="Reference"> 9<link rel="prev" href="buffer_cast/overload2.html" title="buffer_cast (2 of 2 overloads)"> 10<link rel="next" href="buffer_copy/overload1.html" title="buffer_copy (1 of 2 overloads)"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td> 15<td align="center"><a href="../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="buffer_cast/overload2.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="buffer_copy/overload1.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_asio.reference.buffer_copy"></a><a class="link" href="buffer_copy.html" title="buffer_copy">buffer_copy</a> 28</h3></div></div></div> 29<p> 30 <a class="indexterm" name="boost_asio.indexterm.buffer_copy"></a> 31The <code class="computeroutput">boost::asio::buffer_copy</code> 32 function is used to copy bytes from a source buffer (or buffer sequence) 33 to a target buffer (or buffer sequence). 34 </p> 35<p> 36 Copies bytes from a source buffer sequence to a target buffer sequence. 37 </p> 38<pre class="programlisting">template< 39 typename <a class="link" href="MutableBufferSequence.html" title="Mutable buffer sequence requirements">MutableBufferSequence</a>, 40 typename <a class="link" href="ConstBufferSequence.html" title="Constant buffer sequence requirements">ConstBufferSequence</a>> 41std::size_t <a class="link" href="buffer_copy/overload1.html" title="buffer_copy (1 of 2 overloads)">buffer_copy</a>( 42 const MutableBufferSequence & target, 43 const ConstBufferSequence & source); 44 <span class="emphasis"><em>» <a class="link" href="buffer_copy/overload1.html" title="buffer_copy (1 of 2 overloads)">more...</a></em></span> 45</pre> 46<p> 47 Copies a limited number of bytes from a source buffer sequence to a target 48 buffer sequence. 49 </p> 50<pre class="programlisting">template< 51 typename <a class="link" href="MutableBufferSequence.html" title="Mutable buffer sequence requirements">MutableBufferSequence</a>, 52 typename <a class="link" href="ConstBufferSequence.html" title="Constant buffer sequence requirements">ConstBufferSequence</a>> 53std::size_t <a class="link" href="buffer_copy/overload2.html" title="buffer_copy (2 of 2 overloads)">buffer_copy</a>( 54 const MutableBufferSequence & target, 55 const ConstBufferSequence & source, 56 std::size_t max_bytes_to_copy); 57 <span class="emphasis"><em>» <a class="link" href="buffer_copy/overload2.html" title="buffer_copy (2 of 2 overloads)">more...</a></em></span> 58</pre> 59<p> 60 The <code class="computeroutput">buffer_copy</code> function is available in two forms: 61 </p> 62<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 63<li class="listitem"> 64 A 2-argument form: <code class="computeroutput">buffer_copy(target, source)</code> 65 </li> 66<li class="listitem"> 67 A 3-argument form: <code class="computeroutput">buffer_copy(target, source, max_bytes_to_copy)</code> 68 </li> 69</ul></div> 70<p> 71 Both forms return the number of bytes actually copied. The number of bytes 72 copied is the lesser of: 73 </p> 74<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 75<li class="listitem"> 76 <code class="computeroutput">buffer_size(target)</code> 77 </li> 78<li class="listitem"> 79 <code class="computeroutput">buffer_size(source)</code> 80 </li> 81<li class="listitem"> 82 <code class="computeroutput">If</code> specified, <code class="computeroutput">max_bytes_to_copy</code>. 83 </li> 84</ul></div> 85<p> 86 This prevents buffer overflow, regardless of the buffer sizes used in the 87 copy operation. 88 </p> 89<p> 90 Note that <a class="link" href="buffer_copy.html" title="buffer_copy"><code class="computeroutput">buffer_copy</code></a> 91 is implemented in terms of <code class="computeroutput">memcpy</code>, and consequently it cannot 92 be used to copy between overlapping memory regions. 93 </p> 94<h5> 95<a name="boost_asio.reference.buffer_copy.h0"></a> 96 <span class="phrase"><a name="boost_asio.reference.buffer_copy.requirements"></a></span><a class="link" href="buffer_copy.html#boost_asio.reference.buffer_copy.requirements">Requirements</a> 97 </h5> 98<p> 99 <span class="emphasis"><em>Header: </em></span><code class="literal">boost/asio/buffer.hpp</code> 100 </p> 101<p> 102 <span class="emphasis"><em>Convenience header: </em></span><code class="literal">boost/asio.hpp</code> 103 </p> 104</div> 105<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 106<td align="left"></td> 107<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 108 Kohlhoff<p> 109 Distributed under the Boost Software License, Version 1.0. (See accompanying 110 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 111 </p> 112</div></td> 113</tr></table> 114<hr> 115<div class="spirit-nav"> 116<a accesskey="p" href="buffer_cast/overload2.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="buffer_copy/overload1.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 117</div> 118</body> 119</html> 120