| Home | Libraries | People | FAQ | More

### buffer_copy

The `boost::asio::buffer_copy` function is used to copy bytes from a source buffer (or buffer sequence) to a target buffer (or buffer sequence).

    std::size_t buffer_copy(
        const mutable_buffer & target,
        const const_buffer & source);
      » more...

    std::size_t buffer_copy(
        const mutable_buffer & target,
        const const_buffers_1 & source);
      » more...

    std::size_t buffer_copy(
        const mutable_buffer & target,
        const mutable_buffer & source);
      » more...

    std::size_t buffer_copy(
        const mutable_buffer & target,
        const mutable_buffers_1 & source);
      » more...

    template<
        typename ConstBufferSequence>
    std::size_t buffer_copy(
        const mutable_buffer & target,
        const ConstBufferSequence & source);
      » more...

    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const const_buffer & source);
      » more...

    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const const_buffers_1 & source);
      » more...

    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const mutable_buffer & source);
      » more...

    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const mutable_buffers_1 & source);
      » more...

    template<
        typename ConstBufferSequence>
    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const ConstBufferSequence & source);
      » more...

    template<
        typename MutableBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const const_buffer & source);
      » more...

    template<
        typename MutableBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const const_buffers_1 & source);
      » more...

    template<
        typename MutableBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const mutable_buffer & source);
      » more...

    template<
        typename MutableBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const mutable_buffers_1 & source);
      » more...

    template<
        typename MutableBufferSequence,
        typename ConstBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const ConstBufferSequence & source);
      » more...

    std::size_t buffer_copy(
        const mutable_buffer & target,
        const const_buffer & source,
        std::size_t max_bytes_to_copy);
      » more...

    std::size_t buffer_copy(
        const mutable_buffer & target,
        const const_buffers_1 & source,
        std::size_t max_bytes_to_copy);
      » more...

    std::size_t buffer_copy(
        const mutable_buffer & target,
        const mutable_buffer & source,
        std::size_t max_bytes_to_copy);
      » more...

    std::size_t buffer_copy(
        const mutable_buffer & target,
        const mutable_buffers_1 & source,
        std::size_t max_bytes_to_copy);
      » more...

    template<
        typename ConstBufferSequence>
    std::size_t buffer_copy(
        const mutable_buffer & target,
        const ConstBufferSequence & source,
        std::size_t max_bytes_to_copy);
      » more...

    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const const_buffer & source,
        std::size_t max_bytes_to_copy);
      » more...

    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const const_buffers_1 & source,
        std::size_t max_bytes_to_copy);
      » more...

    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const mutable_buffer & source,
        std::size_t max_bytes_to_copy);
      » more...

    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const mutable_buffers_1 & source,
        std::size_t max_bytes_to_copy);
      » more...

    template<
        typename ConstBufferSequence>
    std::size_t buffer_copy(
        const mutable_buffers_1 & target,
        const ConstBufferSequence & source,
        std::size_t max_bytes_to_copy);
      » more...

    template<
        typename MutableBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const const_buffer & source,
        std::size_t max_bytes_to_copy);
      » more...

    template<
        typename MutableBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const const_buffers_1 & source,
        std::size_t max_bytes_to_copy);
      » more...

    template<
        typename MutableBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const mutable_buffer & source,
        std::size_t max_bytes_to_copy);
      » more...

    template<
        typename MutableBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const mutable_buffers_1 & source,
        std::size_t max_bytes_to_copy);
      » more...

    template<
        typename MutableBufferSequence,
        typename ConstBufferSequence>
    std::size_t buffer_copy(
        const MutableBufferSequence & target,
        const ConstBufferSequence & source,
        std::size_t max_bytes_to_copy);
      » more...

The `buffer_copy` function is available in two forms:

- A 2-argument form: `buffer_copy(target, source)`
- A 3-argument form: `buffer_copy(target, source, max_bytes_to_copy)`

Both forms return the number of bytes actually copied. The number of bytes copied is the lesser of:

- `buffer_size(target)`
- `buffer_size(source)`
- `If` specified, `max_bytes_to_copy`.

This prevents buffer overflow, regardless of the buffer sizes used in the copy operation.

Note that `buffer_copy` is implemented in terms of `memcpy`, and consequently it cannot be used to copy between overlapping memory regions.

##### Requirements

Header: `boost/asio/buffer.hpp`

Convenience header: `boost/asio.hpp`