You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "sanjibansg (via GitHub)" <gi...@apache.org> on 2023/02/15 23:48:09 UTC

[GitHub] [arrow] sanjibansg commented on a diff in pull request #14758: ARROW-18119: [C++] Utility method to ensure an array object meetings an alignment requirement

sanjibansg commented on code in PR #14758:
URL: https://github.com/apache/arrow/pull/14758#discussion_r1107857289


##########
cpp/src/arrow/util/align_util.h:
##########
@@ -64,5 +66,23 @@ inline BitmapWordAlignParams BitmapWordAlign(const uint8_t* data, int64_t bit_of
   return p;
 }
 
+template <typename T>
+Status EnsureAlignment(std::shared_ptr<T> object, int64_t alignment,
+                       MemoryPool* memory_pool) {
+  std::vector<std::shared_ptr<Buffer>> buffers_ = object->data()->buffers;
+  for (size_t i = 0; i < buffers_.size(); ++i) {
+    if (buffers_[i]) {
+      auto buffer_address = buffers_[i]->address();
+      if ((buffer_address % alignment) != 0) {
+        ARROW_ASSIGN_OR_RAISE(
+            auto new_buffer, AllocateBuffer(buffers_[i]->size(), alignment, memory_pool));
+        std::memcpy(new_buffer->mutable_data(), buffers_[i]->data(), buffers_[i]->size());
+        object->data()->buffers[i] = std::move(new_buffer);

Review Comment:
   Made the change, thanks!



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org