| Home | Libraries | People | FAQ | More

# boost::asio::buffer

## Detailed Description

The boost::asio::buffer function is used to create a buffer object to represent raw memory, an array of POD elements, or a vector of POD elements.

The simplest use case involves reading or writing a single buffer of a specified size:

     sock.write(boost::asio::buffer(data, size));

In the above example, the return value of boost::asio::buffer meets the requirements of the Const_Buffers concept so that it may be directly passed to the socket's write function. A buffer created for modifiable memory also meets the requirements of the Mutable_Buffers concept.

An individual buffer may be created from a builtin array, std::vector or boost::array of POD elements. This helps prevent buffer overruns by automatically determining the size of the buffer:

     char d1[128];
     size_t bytes_transferred = sock.read(boost::asio::buffer(d1));

     std::vector<char> d2(128);
     bytes_transferred = sock.read(boost::asio::buffer(d2));

     boost::array<char, 128> d3;
     bytes_transferred = sock.read(boost::asio::buffer(d3));

To read or write using multiple buffers (i.e. scatter-gather I/O), multiple buffer objects may be assigned into a container that supports the Mutable_Buffers (for read) or Const_Buffers (for write) concepts:

     char d1[128];
     std::vector<char> d2(128);
     boost::array<char, 128> d3;

     boost::array<mutable_buffer, 3> bufs1 = {
       boost::asio::buffer(d1),
       boost::asio::buffer(d2),
       boost::asio::buffer(d3) };
     bytes_transferred = sock.read(bufs1);

     std::vector<const_buffer> bufs2;
     bufs2.push_back(boost::asio::buffer(d1));
     bufs2.push_back(boost::asio::buffer(d2));
     bufs2.push_back(boost::asio::buffer(d3));
     bytes_transferred = sock.write(bufs2);

## Functions

mutable_buffer_container_1 | boost::asio::buffer (const mutable_buffer &b)
| Create a new modifiable buffer from an existing buffer.
mutable_buffer_container_1 | boost::asio::buffer (const mutable_buffer &b, std::size_t max_size_in_bytes)
| Create a new modifiable buffer from an existing buffer.
const_buffer_container_1 | boost::asio::buffer (const const_buffer &b)
| Create a new non-modifiable buffer from an existing buffer.
const_buffer_container_1 | boost::asio::buffer (const const_buffer &b, std::size_t max_size_in_bytes)
| Create a new non-modifiable buffer from an existing buffer.
mutable_buffer_container_1 | boost::asio::buffer (void *data, std::size_t size_in_bytes)
| Create a new modifiable buffer that represents the given memory range.
const_buffer_container_1 | boost::asio::buffer (const void *data, std::size_t size_in_bytes)
| Create a new non-modifiable buffer that represents the given memory range.
template<typename Pod_Type, std::size_t N>
mutable_buffer_container_1 | boost::asio::buffer (Pod_Type(&data)[N])
| Create a new modifiable buffer that represents the given POD array.
template<typename Pod_Type, std::size_t N>
mutable_buffer_container_1 | boost::asio::buffer (Pod_Type(&data)[N], std::size_t max_size_in_bytes)
| Create a new modifiable buffer that represents the given POD array.
template<typename Pod_Type, std::size_t N>
const_buffer_container_1 | boost::asio::buffer (const Pod_Type(&data)[N])
| Create a new non-modifiable buffer that represents the given POD array.
template<typename Pod_Type, std::size_t N>
const_buffer_container_1 | boost::asio::buffer (const Pod_Type(&data)[N], std::size_t max_size_in_bytes)
| Create a new non-modifiable buffer that represents the given POD array.
template<typename Pod_Type, std::size_t N>
mutable_buffer_container_1 | boost::asio::buffer (boost::array< Pod_Type, N > &data)
| Create a new modifiable buffer that represents the given POD array.
template<typename Pod_Type, std::size_t N>
mutable_buffer_container_1 | boost::asio::buffer (boost::array< Pod_Type, N > &data, std::size_t max_size_in_bytes)
| Create a new modifiable buffer that represents the given POD array.
template<typename Pod_Type, std::size_t N>
const_buffer_container_1 | boost::asio::buffer (boost::array< const Pod_Type, N > &data)
| Create a new non-modifiable buffer that represents the given POD array.
template<typename Pod_Type, std::size_t N>
const_buffer_container_1 | boost::asio::buffer (boost::array< const Pod_Type, N > &data, std::size_t max_size_in_bytes)
| Create a new non-modifiable buffer that represents the given POD array.
template<typename Pod_Type, std::size_t N>
const_buffer_container_1 | boost::asio::buffer (const boost::array< Pod_Type, N > &data)
| Create a new non-modifiable buffer that represents the given POD array.
template<typename Pod_Type, std::size_t N>
const_buffer_container_1 | boost::asio::buffer (const boost::array< Pod_Type, N > &data, std::size_t max_size_in_bytes)
| Create a new non-modifiable buffer that represents the given POD array.
template<typename Pod_Type, typename Allocator>
mutable_buffer_container_1 | boost::asio::buffer (std::vector< Pod_Type, Allocator > &data)
| Create a new modifiable buffer that represents the given POD vector.
template<typename Pod_Type, typename Allocator>
mutable_buffer_container_1 | boost::asio::buffer (std::vector< Pod_Type, Allocator > &data, std::size_t max_size_in_bytes)
| Create a new modifiable buffer that represents the given POD vector.
template<typename Pod_Type, typename Allocator>
const_buffer_container_1 | boost::asio::buffer (const std::vector< Pod_Type, Allocator > &data)
| Create a new non-modifiable buffer that represents the given POD vector.
template<typename Pod_Type, typename Allocator>
const_buffer_container_1 | boost::asio::buffer (const std::vector< Pod_Type, Allocator > &data, std::size_t max_size_in_bytes)
| Create a new non-modifiable buffer that represents the given POD vector.
const_buffer_container_1 | boost::asio::buffer (const std::string &data)
| Create a new non-modifiable buffer that represents the given string.
const_buffer_container_1 | boost::asio::buffer (const std::string &data, std::size_t max_size_in_bytes)
| Create a new non-modifiable buffer that represents the given string.

## Function Documentation

mutable_buffer_container_1 boost::asio::buffer | ( | const mutable_buffer & | b | ) |

Create a new modifiable buffer from an existing buffer.

mutable_buffer_container_1 boost::asio::buffer | ( | const mutable_buffer & | b,
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new modifiable buffer from an existing buffer.

const_buffer_container_1 boost::asio::buffer | ( | const const_buffer & | b | ) |

Create a new non-modifiable buffer from an existing buffer.

const_buffer_container_1 boost::asio::buffer | ( | const const_buffer & | b,
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new non-modifiable buffer from an existing buffer.

mutable_buffer_container_1 boost::asio::buffer | ( | void * | data,
|  | std::size_t | size_in_bytes |
| ) |  |  |

Create a new modifiable buffer that represents the given memory range.

const_buffer_container_1 boost::asio::buffer | ( | const void * | data,
|  | std::size_t | size_in_bytes |
| ) |  |  |

Create a new non-modifiable buffer that represents the given memory range.

template<typename Pod_Type, std::size_t N>

mutable_buffer_container_1 boost::asio::buffer | ( | Pod_Type & | data[N] | ) |

Create a new modifiable buffer that represents the given POD array.

template<typename Pod_Type, std::size_t N>

mutable_buffer_container_1 boost::asio::buffer | ( | Pod_Type & | data[N],
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new modifiable buffer that represents the given POD array.

template<typename Pod_Type, std::size_t N>

const_buffer_container_1 boost::asio::buffer | ( | const Pod_Type & | data[N] | ) |

Create a new non-modifiable buffer that represents the given POD array.

template<typename Pod_Type, std::size_t N>

const_buffer_container_1 boost::asio::buffer | ( | const Pod_Type & | data[N],
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new non-modifiable buffer that represents the given POD array.

template<typename Pod_Type, std::size_t N>

mutable_buffer_container_1 boost::asio::buffer | ( | boost::array< Pod_Type, N > & | data | ) |

Create a new modifiable buffer that represents the given POD array.

template<typename Pod_Type, std::size_t N>

mutable_buffer_container_1 boost::asio::buffer | ( | boost::array< Pod_Type, N > & | data,
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new modifiable buffer that represents the given POD array.

template<typename Pod_Type, std::size_t N>

const_buffer_container_1 boost::asio::buffer | ( | boost::array< const Pod_Type, N > & | data | ) |

Create a new non-modifiable buffer that represents the given POD array.

template<typename Pod_Type, std::size_t N>

const_buffer_container_1 boost::asio::buffer | ( | boost::array< const Pod_Type, N > & | data,
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new non-modifiable buffer that represents the given POD array.

template<typename Pod_Type, std::size_t N>

const_buffer_container_1 boost::asio::buffer | ( | const boost::array< Pod_Type, N > & | data | ) |

Create a new non-modifiable buffer that represents the given POD array.

template<typename Pod_Type, std::size_t N>

const_buffer_container_1 boost::asio::buffer | ( | const boost::array< Pod_Type, N > & | data,
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new non-modifiable buffer that represents the given POD array.

template<typename Pod_Type, typename Allocator>

mutable_buffer_container_1 boost::asio::buffer | ( | std::vector< Pod_Type, Allocator > & | data | ) |

Create a new modifiable buffer that represents the given POD vector.

Note:
  The buffer is invalidated by any vector operation that would also invalidate iterators.

template<typename Pod_Type, typename Allocator>

mutable_buffer_container_1 boost::asio::buffer | ( | std::vector< Pod_Type, Allocator > & | data,
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new modifiable buffer that represents the given POD vector.

Note:
  The buffer is invalidated by any vector operation that would also invalidate iterators.

template<typename Pod_Type, typename Allocator>

const_buffer_container_1 boost::asio::buffer | ( | const std::vector< Pod_Type, Allocator > & | data | ) |

Create a new non-modifiable buffer that represents the given POD vector.

Note:
  The buffer is invalidated by any vector operation that would also invalidate iterators.

template<typename Pod_Type, typename Allocator>

const_buffer_container_1 boost::asio::buffer | ( | const std::vector< Pod_Type, Allocator > & | data,
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new non-modifiable buffer that represents the given POD vector.

Note:
  The buffer is invalidated by any vector operation that would also invalidate iterators.

const_buffer_container_1 boost::asio::buffer | ( | const std::string & | data | ) |

Create a new non-modifiable buffer that represents the given string.

Note:
  The buffer is invalidated by any non-const operation called on the given string object.

const_buffer_container_1 boost::asio::buffer | ( | const std::string & | data,
|  | std::size_t | max_size_in_bytes |
| ) |  |  |

Create a new non-modifiable buffer that represents the given string.

Note:
  The buffer is invalidated by any non-const operation called on the given string object.

| Copyright © 2003 - 2006 Christopher M. Kohlhoff