Is the following a “safe” usage of `UnsafeArrays?
struct SafeUnsafeArray{T, N} <: AbstractArray{T, N}
A::UnsafeArray{T, N}
_A::Vector{UInt8}
end
x = zeros(UInt8, 800)
ptr = Base.unsafe_convert(Ptr{Float64}, x)
u = UnsafeArray(ptr, (100,))
s = SafeUnsafeArray(u, x)
Now, may I pass s
around some functions until I no longer need it, rather than use it only “locally” as suggested by the UnsafeArrays
documentation?
NOTE: I’m fully aware of reinterpret
, but it seems in some of my use-cases, UnsafeArrays
is anywhere from 0 to 30% faster.