@@ -43,7 +43,8 @@ class Status;
43
43
// The following invariant is always true: Size < Capacity
44
44
class ARROW_EXPORT Buffer : public std::enable_shared_from_this<Buffer> {
45
45
public:
46
- Buffer (const uint8_t * data, int64_t size) : data_(data), size_(size), capacity_(size) {}
46
+ Buffer (const uint8_t * data, int64_t size)
47
+ : is_mutable_(false ), data_(data), size_(size), capacity_(size) {}
47
48
virtual ~Buffer ();
48
49
49
50
// An offset into data that is owned by another buffer, but we want to be
@@ -57,6 +58,8 @@ class ARROW_EXPORT Buffer : public std::enable_shared_from_this<Buffer> {
57
58
58
59
std::shared_ptr<Buffer> get_shared_ptr () { return shared_from_this (); }
59
60
61
+ bool is_mutable () const { return is_mutable_; }
62
+
60
63
// Return true if both buffers are the same size and contain the same bytes
61
64
// up to the number of compared bytes
62
65
bool Equals (const Buffer& other, int64_t nbytes) const {
@@ -71,18 +74,22 @@ class ARROW_EXPORT Buffer : public std::enable_shared_from_this<Buffer> {
71
74
(data_ == other.data_ || !memcmp (data_, other.data_ , size_)));
72
75
}
73
76
77
+ // Copy section of buffer into a new Buffer
78
+ Status Copy (int64_t start, int64_t nbytes, MemoryPool* pool,
79
+ std::shared_ptr<Buffer>* out) const ;
80
+
81
+ // Default memory pool
82
+ Status Copy (int64_t start, int64_t nbytes, std::shared_ptr<Buffer>* out) const ;
83
+
74
84
int64_t capacity () const { return capacity_; }
75
85
const uint8_t * data () const { return data_; }
76
86
77
87
int64_t size () const { return size_; }
78
88
79
- // Returns true if this Buffer is referencing memory (possibly) owned by some
80
- // other buffer
81
- bool is_shared () const { return static_cast <bool >(parent_); }
82
-
83
89
const std::shared_ptr<Buffer> parent () const { return parent_; }
84
90
85
91
protected:
92
+ bool is_mutable_;
86
93
const uint8_t * data_;
87
94
int64_t size_;
88
95
int64_t capacity_;
@@ -94,10 +101,16 @@ class ARROW_EXPORT Buffer : public std::enable_shared_from_this<Buffer> {
94
101
DISALLOW_COPY_AND_ASSIGN (Buffer);
95
102
};
96
103
104
+ // Construct a view on passed buffer at the indicated offset and length. This
105
+ // function cannot fail and does not error checking (except in debug builds)
106
+ std::shared_ptr<Buffer> SliceBuffer (
107
+ const std::shared_ptr<Buffer>& buffer, int64_t offset, int64_t length);
108
+
97
109
// A Buffer whose contents can be mutated. May or may not own its data.
98
110
class ARROW_EXPORT MutableBuffer : public Buffer {
99
111
public:
100
112
MutableBuffer (uint8_t * data, int64_t size) : Buffer(data, size) {
113
+ is_mutable_ = true ;
101
114
mutable_data_ = data;
102
115
}
103
116
0 commit comments