Mojo function
uninit_copy_n
uninit_copy_n[T: Copyable, //, *, overlapping: Bool](*, dest: UnsafePointer[T, dest.origin], src: UnsafePointer[T, src.origin], 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
memcpy (or memmove when overlapping=True) operation. Otherwise, it
calls init_pointee_copy() 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
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 (
Copyable): The type of values to copy, which must beCopyable. - overlapping (
Bool): If False, the function assumessrcanddestdo not overlap and usesmemcpy. If True, the function assumessrcanddestmay overlap and usesmemmoveto 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 copy.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!