Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ardieb opened this issue Jun 25, 2020 · 1 comment

Comments

@ardieb
Copy link

ardieb commented Jun 25, 2020

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?

buffer->unshare();
MyBuffer payload;
payload.reset(buffer->writableData(), buffer->length());
buffer->markExternallyShared();
@afrind
Copy link
Contributor

afrind commented Jun 29, 2020

I'm not sure you can get IOBuf to release its underlying buffer, but you can construct one wrapping a buffer that you own (so it won't delete it at destruction time). See IOBuf::wrapBuffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants