MCPcopy Create free account
hub / github.com/apache/arrow / FromVector

Function FromVector

cpp/src/arrow/buffer.h:163–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161 /// \return a new Buffer instance
162 template <typename T>
163 static std::shared_ptr<Buffer> FromVector(std::vector<T> vec) {
164 static_assert(std::is_trivial_v<T>,
165 "Buffer::FromVector can only wrap vectors of trivial objects");
166
167 if (vec.empty()) {
168 return std::shared_ptr<Buffer>{new Buffer()};
169 }
170
171 auto* data = reinterpret_cast<uint8_t*>(vec.data());
172 auto size_in_bytes = static_cast<int64_t>(vec.size() * sizeof(T));
173 return std::shared_ptr<Buffer>{
174 new Buffer{data, size_in_bytes},
175 // Keep the vector's buffer alive inside the shared_ptr's destructor until after
176 // we have deleted the Buffer. Note we can't use this trick in FromString since
177 // std::string's data is inline for short strings so moving invalidates pointers
178 // into the string's buffer.
179 [vec = std::move(vec)](Buffer* buffer) { delete buffer; }};
180 }
181
182 /// \brief Create buffer referencing typed memory with some length without
183 /// copying

Callers 4

MakeBinaryViewArrayFunction · 0.85
SetUpMethod · 0.85
ASSERT_OK_AND_ASSIGNFunction · 0.85

Calls 3

emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by 4

MakeBinaryViewArrayFunction · 0.68
SetUpMethod · 0.68
ASSERT_OK_AND_ASSIGNFunction · 0.68