| 165 | |
| 166 | A simple shared buffer. |
| 167 | |
| 168 | Important: if not shared, a buffer is writable. After the buffer is shared, the buffer is immutable. It uses shared_ptr/default allocators and prints error messages to `cerr` if buffers leaked at the end of the program (only in `debug` mode). |
| 169 | |
| 170 | Typical operations: |
| 171 | |
| 172 | - shared_buffer_t(size_t size) |
| 173 | - creates a shared buffer of a specific size |
| 174 | - allocates memory and frees after destruction |
| 175 | - shared_buffer_t(unsigned char* buffer, size_t size) |
| 176 | - creates a shared buffer from existing data |
| 177 | - transfers ownership |
| 178 | - frees memory after destruction |
| 179 | - shared_buffer_t shared_buffer_t::operator()(size_t index, size_t size = 0) |
| 180 | - return sub-buffer |
| 181 | - example: `shared_buffer_t sub_buff = buff(15)`; |
| 182 | - const uint8_t* data = buff.data(); |
| 183 | - access data as array (read-only) |
| 184 | - uint8_t* data = buff.mutable_data(); |
| 185 | - access data as array (writable) |
| 186 | - NOTE: only if buffer is not shared, yet |
| 187 | |
| 188 | For more information refer to the source code: `ariba/utility/transport/messages/shared_buffer.hpp` |