tustvold commented on code in PR #3756:
URL: https://github.com/apache/arrow-rs/pull/3756#discussion_r1118793512
##########
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:
The docs for
[`dealloc`](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html#safety-2)
are authoritative here
> ptr must denote a block of memory currently allocated via this allocator
> layout must be the same layout that was used to allocate that block of
memory
The layout of arrays, vecs, etc... is fixed and defined by
[`Layout::array`](https://doc.rust-lang.org/std/alloc/struct.Layout.html#method.array).
As such we are fine provided we obey the same logic.
--
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]