pitrou commented on code in PR #36418:
URL: https://github.com/apache/arrow/pull/36418#discussion_r1252060072
##########
cpp/src/arrow/buffer.h:
##########
@@ -137,6 +139,25 @@ class ARROW_EXPORT Buffer {
/// \return a new Buffer instance
static std::shared_ptr<Buffer> FromString(std::string data);
+ /// \brief Construct an immutable buffer that takes ownership of the contents
+ /// of an std::vector (without copying it).
+ ///
+ /// \param[in] data a string to own
+ /// \return a new Buffer instance
+ template <typename T>
+ static std::shared_ptr<Buffer> FromVector(std::vector<T> vec) {
+ auto* data = reinterpret_cast<uint8_t*>(vec.data());
+ auto size = static_cast<int64_t>(vec.size());
+ return std::shared_ptr<Buffer>(
+ new Buffer{data, size},
+ [vec = std::move(
+ vec) // Keep the vector's buffer alive inside the destructor
until after we
+ // have deleted the Buffer. Note we can't use this trick in
FromString
+ // since std::string's data is inline for short strings so
moving
+ // invalidates pointers into the string's buffer.
Review Comment:
Or just use `// clang-format off` / `// clang-format on` around those lines.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]