Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
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