-
Notifications
You must be signed in to change notification settings - Fork 13.7k
ptr::copy_nonoverlapping
is not memcpy
#113347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "memcpy-\u3058\u3083\u306A\u3044"
Changes from all commits
73163f8
cb42825
313ab9c
8a7f449
3cb3b0e
24fe39f
9c35d94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2574,14 +2574,9 @@ pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) - | |
/// | ||
/// For regions of memory which might overlap, use [`copy`] instead. | ||
/// | ||
/// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but | ||
/// with the argument order swapped. | ||
/// | ||
/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the | ||
/// requirements of `T`. The initialization state is preserved exactly. | ||
/// | ||
/// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy | ||
/// | ||
/// # Safety | ||
/// | ||
/// Behavior is undefined if any of the following conditions are violated: | ||
|
@@ -2603,6 +2598,8 @@ pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) - | |
/// | ||
/// Note that even if the effectively copied size (`count * size_of::<T>()`) is | ||
/// `0`, the pointers must be non-null and properly aligned. | ||
/// In this case, the pointers may share the same address, as | ||
/// a region of 0 bytes does not overlap with a region of 0 bytes. | ||
/// | ||
/// [`read`]: crate::ptr::read | ||
/// [read-ownership]: crate::ptr::read#ownership-of-the-returned-value | ||
|
@@ -2684,18 +2681,15 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us | |
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source | ||
/// and destination may overlap. | ||
/// | ||
/// If the source and destination will *never* overlap, | ||
/// [`copy_nonoverlapping`] can be used instead. | ||
/// | ||
/// `copy` is semantically equivalent to C's [`memmove`], but with the argument | ||
/// order swapped. Copying takes place as if the bytes were copied from `src` | ||
/// to a temporary array and then copied from the array to `dst`. | ||
/// `copy` may temporarily use additional space to copy bytes from `src` into an array, before | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't it just copy forwards/backwards depending on which region is "lower"? I don't think you ever need a temporary array? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. arguably a register is in fact a "temporary array", but you're right, I think. |
||
/// copying them to `dst`. This lets `copy` correctly handle overlapping locations. | ||
/// If `src` and `dst` *never* overlap, [`copy_nonoverlapping`] may be used to avoid overhead. | ||
/// Note that in many cases, this additional overhead can be removed or reduced by the compiler, | ||
/// as this is an "intrinsic function" implemented directly through the compiler. | ||
/// | ||
/// The copy is "untyped" in the sense that data may be uninitialized or otherwise violate the | ||
/// requirements of `T`. The initialization state is preserved exactly. | ||
/// | ||
/// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove | ||
/// | ||
/// # Safety | ||
/// | ||
/// Behavior is undefined if any of the following conditions are violated: | ||
|
@@ -2771,10 +2765,8 @@ pub const unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) { | |
/// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to | ||
/// `val`. | ||
/// | ||
/// `write_bytes` is similar to C's [`memset`], but sets `count * | ||
/// size_of::<T>()` bytes to `val`. | ||
/// | ||
/// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset | ||
/// Note that this means that if `T` is multiple bytes, each byte is set to the same value, | ||
/// which may be interpreted to mean a very different value when interpreted as `T`. | ||
/// | ||
/// # Safety | ||
/// | ||
|
Uh oh!
There was an error while loading. Please reload this page.