Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <arrow/buffer.h>
- #include <memory>
- #include <iostream>
- using namespace arrow;
- using namespace std;
- auto main(int argc, char* argv[]) -> int {
- int64_t size = 16;
- auto* memory = static_cast<uint8_t*>(malloc(size));
- shared_ptr<Buffer> mutable_slice;
- {
- // owns the memory, but just by convention
- auto mutable_buffer = make_shared<MutableBuffer>(memory, size);
- strcpy(reinterpret_cast<char*>(mutable_buffer->mutable_data()), "asdf");
- // doesn't own the memory nor has any insight in the parent
- mutable_slice = SliceMutableBuffer(mutable_buffer, 0, 2);
- cout << mutable_slice->data() << endl;
- // we since we own the memory we release it beforehand
- free(memory);
- }
- // no way of knowing if it is safe to do
- cout << mutable_slice->data() << endl;
- }
Add Comment
Please, Sign In to add comment