IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0
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).

uninit_copy_n

def uninit_copy_n[T: Copyable, //, *, overlapping: Bool](*, dest: Pointer[T], src: Pointer[T], count: Int)

Copy count values from src into memory at dest.

This function creates copies of count values from the source memory in the destination memory. After this call, both source and destination values are valid and initialized.

For types with trivial copy constructors, this is optimized to a single unsafe_memcpy (or memmove when overlapping=True) operation. Otherwise, it calls unsafe_write() on 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:

  • 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.

Deprecated: 'uninit_copy_n' is deprecated, use 'unsafe_uninit_copy_n' instead

Parameters:

  • T (Copyable): The type of values to copy, which must be Copyable.
  • overlapping (Bool): If False, the function assumes src and dest do not overlap and uses unsafe_memcpy. If True, the function assumes src and dest may overlap and uses memmove to 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 copy.