Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

buffer_cast

The boost::asio::buffer_cast function is used to obtain a pointer to the underlying memory region associated with a buffer.

template<
    typename PointerToPodType>
PointerToPodType buffer_cast(
    const mutable_buffer & b);
  » more...

template<
    typename PointerToPodType>
PointerToPodType buffer_cast(
    const const_buffer & b);
  » more...
Examples:

To access the memory of a non-modifiable buffer, use:

boost::asio::const_buffer b1 = ...;
const unsigned char* p1 = boost::asio::buffer_cast<const unsigned char*>(b1);

To access the memory of a modifiable buffer, use:

boost::asio::mutable_buffer b2 = ...;
unsigned char* p2 = boost::asio::buffer_cast<unsigned char*>(b2);

The boost::asio::buffer_cast function permits violations of type safety, so uses of it in application code should be carefully considered.

Requirements

Header: boost/asio/buffer.hpp

Convenience header: boost/asio.hpp


PrevUpHomeNext