facebook / facebook/folly

Transferring ownership of an IOBuf to another data structure with as few memcpy as possible

Open
#1,399 1 comment 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.