felipecrv commented on code in PR #39772:
URL: https://github.com/apache/arrow/pull/39772#discussion_r1470041064


##########
cpp/src/arrow/device.h:
##########
@@ -363,4 +363,22 @@ class ARROW_EXPORT CPUMemoryManager : public MemoryManager 
{
 ARROW_EXPORT
 std::shared_ptr<MemoryManager> default_cpu_memory_manager();
 
+/// \brief Copy all buffers of an array to destination MemoryManager
+///
+/// This utilizes MemoryManager::CopyBuffer to create a new Array recursively 
copying
+/// all buffers, and all children buffers, to the destination MemoryManager. 
This
+/// includes any dictionaries if applicable.
+ARROW_EXPORT
+Result<std::shared_ptr<Array>> CopyArrayTo(const Array& array,

Review Comment:
   `CopyOrView` creates weird expectations about the returned values: if you 
copy, the caller can have unique ownership of the array, if it's a view, you 
have to share. Another possible solution to the problem @pitrou brought up is 
failing the operation if source and destination are the same device, forcing 
the caller to be aware of data location before it calls the copy function. The 
compromise solution: provide `CopyOrView` in terms of a `CopyArrayTo` that 
returns a bad status when called for arrays on the same device.
   
   (I understand that the memory model in Arrow is that every buffer is 
immutable and always shared, but we might want these rules to be relaxed at 
some point.)



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