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

**URL:** <https://discourse.julialang.org/t/memviews-jl-practical-simple-low-level-views-into-memory/116043>\
**Category:** Package Announcements\
**Created:** [June 22, 2024, 10:28am UTC](https://discourse.julialang.org/t/memviews-jl-practical-simple-low-level-views-into-memory/116043 "2024-06-22T10:28:04Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![jakobnissen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobnissen/32/13477_2.png) [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)\
**Post date:** [June 22, 2024, 3:04pm UTC](https://discourse.julialang.org/t/memviews-jl-practical-simple-low-level-views-into-memory/116043/3 "2024-06-22T15:04:17Z")

</div>

See [the Limitations section of the README](https://github.com/BioJulia/MemViews.jl?tab=readme-ov-file#limitations) and also [this Discourse thread](https://discourse.julialang.org/t/memory-aliasing-rules-and-reinterpret/109875)

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](https://github.com/JuliaLang/julia/pull/54099) states that it’s UB to cause:

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

---

_[View the full topic](https://discourse.julialang.org/t/memviews-jl-practical-simple-low-level-views-into-memory/116043)._
