For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
unsafe_uninit_move_n
def unsafe_uninit_move_n[T: Movable, //, *, overlapping: Bool](*, dest: Pointer[T], src: Pointer[T], 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
unsafe_memcpy (or unsafe_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
unsafe_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:
destmust point to a valid memory region with space for at leastcountelements of typeT.srcmust point to a valid memory region containing at leastcountinitialized elements of typeT.- If
overlapping=False, thesrcanddestmemory regions must not overlap. Overlapping regions withoverlapping=Falseis undefined behavior.
Parameters:
- T (
Movable): The type of values to move, which must beMovable. - overlapping (
Bool): If False, the function assumessrcanddestdo not overlap and usesunsafe_memcpy. If True, the function assumessrcanddestmay overlap and usesunsafe_memmoveto handle this safely.
Args:
- dest (
Pointer[T]): Pointer to the destination memory region. - src (
Pointer[T]): Pointer to the source memory region. Must point to initialized values. - count (
Int): The number of elements to move.