MemViews.jl - practical, simple, low-level views into Memory

See the Limitations section of the README and also this Discourse thread

I also tried to make that work, but couldn’t. The reason is that it’s not possible to construct a MemoryRef{B} from a MemoryRef{A}.
It can be done incurring an allocation by making a new Memory object that aliases the old one, and then taking a view of that.
However, the docs of unsafe_wrap states:

Unlike unsafe_load and unsafe_store!, the programmer is responsible also
for ensuring that the underlying data is not accessed through two arrays of different element type, similar to the strict aliasing rule in C.

I believe it might be UB to create a MemView{A} object pointing to `Memory{B}. The proposed docs on UB in Julia states that it’s UB to cause:

Violations of TBAA guarantees (e.g. using unsafe_wrap)

1 Like