Skip to main content

Mojo function

uninit_move_n

uninit_move_n[T: Movable, //, *, overlapping: Bool](*, dest: UnsafePointer[T, dest.origin], src: UnsafePointer[T, src.origin], count: Int)

Move count values from src into memory at dest.

This function transfers ownership of count values from the source memory to the destination memory. After this call, the source values should be treated as uninitialized, and the destination values are valid and initialized.

For types with trivial move constructors, this is optimized to a single memcpy (or memmove when overlapping=True) operation. Otherwise, it manually moves each element.

The destination memory is treated as a raw span of bits to write to. Any existing values at dest are silently overwritten without being destroyed. For types with non-trivial destructors, this can cause memory leaks. Call destroy_n() on the destination region first if it contains initialized values that need cleanup. For trivial types like Int, this is not a concern.

Safety:

  • dest must point to a valid memory region with space for at least count elements of type T.
  • src must point to a valid memory region containing at least count initialized elements of type T.
  • If overlapping=False, the src and dest memory regions must not overlap. Overlapping regions with overlapping=False is undefined behavior.

Parameters:

  • T (Movable): The type of values to move, which must be Movable.
  • overlapping (Bool): If False, the function assumes src and dest do not overlap and uses memcpy. If True, the function assumes src and dest may overlap and uses memmove to handle this safely.

Args:

  • dest (UnsafePointer): Pointer to the destination memory region.
  • src (UnsafePointer): Pointer to the source memory region. Must point to initialized values.
  • count (Int): The number of elements to move.

Was this page helpful?