Guest User

Untitled

a guest
Apr 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <arrow/buffer.h>
  2. #include <memory>
  3. #include <iostream>
  4.  
  5. using namespace arrow;
  6. using namespace std;
  7.  
  8. auto main(int argc, char* argv[]) -> int {
  9. int64_t size = 16;
  10. auto* memory = static_cast<uint8_t*>(malloc(size));
  11. shared_ptr<Buffer> mutable_slice;
  12. {
  13. // owns the memory, but just by convention
  14. auto mutable_buffer = make_shared<MutableBuffer>(memory, size);
  15. strcpy(reinterpret_cast<char*>(mutable_buffer->mutable_data()), "asdf");
  16.  
  17. // doesn't own the memory nor has any insight in the parent
  18. mutable_slice = SliceMutableBuffer(mutable_buffer, 0, 2);
  19. cout << mutable_slice->data() << endl;
  20.  
  21. // we since we own the memory we release it beforehand
  22. free(memory);
  23. }
  24.  
  25. // no way of knowing if it is safe to do
  26. cout << mutable_slice->data() << endl;
  27. }
Add Comment
Please, Sign In to add comment