westonpace commented on code in PR #14758:
URL: https://github.com/apache/arrow/pull/14758#discussion_r1147135735
##########
cpp/src/arrow/util/align_util_test.cc:
##########
@@ -59,6 +63,18 @@ void CheckBitmapWordAlign(const uint8_t* data, int64_t
bit_offset, int64_t lengt
}
}
+arrow::Result<std::shared_ptr<Array>>
CreateUnalignedArray(std::shared_ptr<Array> array) {
+ BufferVector sliced_buffers(array->data()->buffers.size(), nullptr);
+ for (std::size_t i = 0; i < array->data()->buffers.size(); ++i) {
+ if (array->data()->buffers[i]) {
+ sliced_buffers[i] = array->data()->buffers[i]->CopySlice(0,
2).MoveValueUnsafe();
Review Comment:
Sorry, this comment was meant to accompany the review but it seems Github
swallowed it. `CopySafe` allocates a new buffer and copies the slice into this
new buffer. The newly allocated buffer will have at least 64 byte alignment
but, depending on the system allocator (or just bad luck), this alignment could
be greater.
Instead you should use
[`SliceBuffer`](https://github.com/apache/arrow/blob/main/cpp/src/arrow/buffer.h#L322).
However, `SliceBuffer` returns a view only (this is inevitable here) so you
need to make sure to keep the original array alive. To do that change this
method to accept `const Array&` instead of `std::shared_ptr<Array>`. Then you
should be ok.
--
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]