unsafe_copy!(dest::Array, d, src::Array, so,
unsafe_copy!(dest::Array, do, src::Array, so, N)
Copy N
elements from a source array to a destination, starting at offset so
in the source and do
in the destination (1-indexed).
The unsafe
prefix on this function indicates that no validation is performed to ensure that N is inbounds on either array. Incorrect usage may corrupt or segfault your program, in the same manner as C.
Examples
-
Unsafe copy of elements from one array to another:
julia> src = [1, 2, 3, 4, 5]; julia> dest = zeros(Int, 5); julia> unsafe_copy!(dest, 1, src, 1, 5) 5-element Array{Int64,1}: 1 2 3 4 5
This example performs an unsafe copy of all elements from the source array
src
to the destination arraydest
. -
Copying a subset of elements using offsets:
julia> src = [10, 20, 30, 40, 50]; julia> dest = zeros(Int, 3); julia> unsafe_copy!(dest, 1, src, 2, 3) 3-element Array{Int64,1}: 20 30 40
In this example, the unsafe copy is performed starting from the second element of the source array (
src
) and copied to the destination array (dest
) starting from the first index. - Unsafe copy with overlapping arrays:
julia> src = [1, 2, 3, 4, 5]; julia> dest = [10, 20, 30, 40, 50]; julia> unsafe_copy!(dest, 3, src, 2, 4) 5-element Array{Int64,1}: 10 20 2 3 4
This example demonstrates an unsafe copy where the copied elements overlap with the existing elements in the destination array.
Note: It is important to exercise caution while using unsafe_copy!
as no bounds checking is performed. Incorrect usage may lead to memory corruption or program crashes.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.