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

[GitHub] [arrow-rs] ritchie46 commented on a diff in pull request #3756: Zero-copy Vec conversion (#3516) (#1176)

ritchie46 commented on code in PR #3756:
URL: https://github.com/apache/arrow-rs/pull/3756#discussion_r1118869920


##########
arrow-buffer/src/buffer/immutable.rs:
##########
@@ -69,6 +71,21 @@ impl Buffer {
         }
     }
 
+    /// Create a [`Buffer`] from the provided `Vec` without copying
+    #[inline]
+    pub fn from_vec<T: ArrowNativeType>(vec: Vec<T>) -> Self {
+        // Safety
+        // Vec::as_ptr guaranteed to not be null and ArrowNativeType are trivially transmutable
+        let ptr = unsafe { NonNull::new_unchecked(vec.as_ptr() as _) };

Review Comment:
   Do we plan to store/create from layouts other than `Vec`? Otherwise we can just create from `Vec`, forget the owned Vector.
   
   On `drop` we recreate the `Vec` so that the drop sequence is executed.
   
   This would defer all this logic to the implementation in `std`.



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