tadeja commented on code in PR #41870:
URL: https://github.com/apache/arrow/pull/41870#discussion_r3174453434


##########
cpp/src/arrow/tensor.cc:
##########
@@ -367,42 +394,42 @@ Status RecordBatchToTensor(const RecordBatch& batch, bool 
null_to_nan, bool row_
   }
 
   // Allocate memory
-  ARROW_ASSIGN_OR_RAISE(
-      std::shared_ptr<Buffer> result,
-      AllocateBuffer(result_type->bit_width() * batch.num_columns() * 
batch.num_rows(),
-                     pool));
+  ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> result,
+                        AllocateBuffer(result_type->bit_width() *
+                                           container.num_columns() * 
container.num_rows(),
+                                       pool));

Review Comment:
   Mr. Opus convinced me `AllocateBuffer` takes bytes not bits, see example 
here:
   
https://github.com/apache/arrow/blob/c13f3bc96c5d9985e49ef31cc0c232e1ffec379a/cpp/src/arrow/compute/kernels/ree_util_internal.cc#L42
   supposedly already from `RecordBatchToTensor` and the fix is to update it to 
byte_width to avoid over-allocating 8xtimes
   
   ```suggestion
     ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> result,
                           AllocateBuffer(result_type->byte_width() *
                                              container.num_columns() * 
container.num_rows(),
                                          pool));
   ```



-- 
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]

Reply via email to