Dereferencing an Array of Struct Pointer

Uhm… You are right. The reason is that in the array tests there are not stored the objects Test themselves, but just pointers to them, so there is a double indirection (because they are mutable, which I didn’t notice).

The following works, but seem extremely fragile, so there must be a better solution:

p = Base.unsafe_convert(Ptr{Ptr{Test}}, pointer(tests, 1))
unsafe_load(unsafe_load(p))

Edit

This works as well and is a bit cleaner:

p = Base.unsafe_convert(Ptr{Test}, Ref(tests, 1))
unsafe_load(p)
2 Likes