nstd_core_mem_swap

Function nstd_core_mem_swap 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nstd_core_mem_swap( x: *mut NSTDByte, y: *mut NSTDByte, num: NSTDUInt, )
Available on crate feature core only.
Expand description

Swaps num bytes between the memory buffers x and y.

§Parameters:

  • NSTDByte *x - A pointer to the first memory buffer.

  • NSTDByte *y - A pointer to the second memory buffer.

  • NSTDUInt num - The number of bytes to swap.

§Safety

This function is highly unsafe as it does not know how large either of the memory buffers are, quickly leading to undefined behavior if this function ends up reading or writing past the end of a buffer.

§Example

use nstd_sys::core::mem::nstd_core_mem_swap;

unsafe {
    let mut buf1 = [0u8; 25];
    let mut buf2 = [u8::MAX; 25];
    nstd_core_mem_swap(buf1.as_mut_ptr(), buf2.as_mut_ptr(), 25);
    assert!(buf1 == [u8::MAX; 25] && buf2 == [0u8; 25]);
}