Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

buffer_cast

(Deprecated: Use the data() member function.) The boost::asio::buffer_cast function is used to obtain a pointer to the underlying memory region associated with a buffer.

Cast a non-modifiable buffer to a specified pointer to POD type.

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