My length is Cint.
I try out cast directly as you did and errors still same.
But im using c++ to call julia and have pure messaging (dot get correct way to catch exceptions, JL_TRY is strange - it could be used only once)
fatal: error thrown and no exception handler available.
MethodError(f=UnsafeArrays.UnsafeArray{Float64, 1}, args=(0x000001ef854c8cb0, 3), world=0x00000000000068ac)
jl_method_error_bare at C:/workdir/src\gf.c:2254
jl_method_error at C:/workdir/src\gf.c:2272
jl_lookup_generic_ at C:/workdir/src\gf.c:3106
ijl_apply_generic at C:/workdir/src\gf.c:3121
Here’s a minimal demo of how to construct an UnsafeArray from a Ptr:
julia> using UnsafeArrays
julia> let N = 10, T = Float64
_ptr = Libc.malloc(sizeof(T) * N)
ptr = convert(Ptr{T}, _ptr)
A = UnsafeArray(ptr, (N,))
A .= 1
@show sum(A)
Libc.free(ptr)
end
sum(A) = 10.0
the important thing to know here is that you have to call UnsafeArray(::Ptr{T}, ::NTuple{N, Int}) to construct an UnsafeArray{T, N}. For some reason they don’t have a method for UnsafeArray{T, N}(::Ptr, dims...). That’s why I did the convert step in the above code.
I’d recommend that at least while debugging your code and learning to make it work, you run your code within julia. It’ll make it easier to get error messages that make sense and get people to help you.