Copying bytes from AbstractVector to Ptr

If you want to have it faster, you can use @inbounds. Ignoring manual bounds checking, that gives

function unsafe_read3!(
        dest::Ptr{T},
        src::AbstractVector{T},
        so::Integer,
        nbytes::Integer) where T
    for i in 1:nbytes
        unsafe_store!(dest, @inbounds(src[so+i-1]), i)
    end
end

With nbytes = 4000, I get

julia> @b unsafe_read1!($d, $s, 1, $nbytes)
2.992 μs (1 allocs: 4.062 KiB)

julia> @b unsafe_read3!($d, $s, 1, $nbytes)
1.845 μs
2 Likes