Transferring ownership of an IOBuf to another data structure with as few memcpy as possible
Open
- Dominant language
- C++
- Stars
- 30.5k
- Forks
- 5.9k
- PR merge metrics
- No merged PRs in 30d
Description
I need to transfer ownership back and forth between a immutable data container and IOBuf. The container maintains contiguous segments of memory allocated using std::malloc. The data structure has a method `reset` that takes ownership of the provided uint8_t pointer and the given length of memory. I've tried the following code, which causes a segfault. The IOBuf is not chained and is stored in a unique_ptr. Is there a standard way of releasing ownership of the underlying data in IOBuf?
```cpp
buffer->unshare();
MyBuffer payload;
payload.reset(buffer->writableData(), buffer->length());
buffer->markExternallyShared();
```
Contributor guide
Assessment
This issue has not been assessed yet.