# Memory buffer type?

**URL:** <https://discourse.julialang.org/t/memory-buffer-type/15345>\
**Category:** Internals & Design\
**Created:** [September 22, 2018, 5:41pm UTC](https://discourse.julialang.org/t/memory-buffer-type/15345 "2018-09-22T17:41:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![loisel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loisel/32/50626_2.png) [@loisel](https://discourse.julialang.org/u/loisel)\
**Post date:** [September 22, 2018, 5:41pm UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/1 "2018-09-22T17:41:10Z")

</div>

I thought I saw somewhere that multidimensional arrays ought to be built on top of arrays of bytes. This would be useful to me for a thing. Is this happening?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 22, 2018, 7:11pm UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/2 "2018-09-22T19:11:09Z")

</div>

My computer doesn’t have bytes.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 22, 2018, 7:44pm UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/3 "2018-09-22T19:44:45Z")

</div>

More seriously, you might be referring to the difference between storing a multidimensional array as a “array of arrays” vs. as a contiguous sequence of elements in memory. Julia’s multidimensional arrays use the latter format, with column-major ordering.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 22, 2018, 8:00pm UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/4 "2018-09-22T20:00:54Z")

</div>

Or perhaps this is about having a julia memory buffer datastructure which `Array` is implemented (in Julia) on top of?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 22, 2018, 8:46pm UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/5 "2018-09-22T20:46:00Z")

</div>

You can already wrap an array around an existing memory buffer with `unsafe_wrap`

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 23, 2018, 12:31am UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/6 "2018-09-23T00:31:35Z")

</div>

It strongly depend on what exactly is useful to you “for a thing”.

Array on top of user accessable byte buffer is basically the new reinterpret array. I don’t believe that’ll replace normal arrays ever since doing it means people will easily write code that can crash. It also go directly against the idea behind the reinterpret array since all tbaa will be lost.

What could happen but I don’t think is worked on by anyone is implement array on top of fixed size 1-d array. It’ll be as type safe as current implementation but might allow more direct access of the array implementation from the optimizer.

Accessing underlying storage is always possible since forever. `pointer` is even much more safe to use now with `GC.@preserve`.

---

<div class="post-metadata">

**Author:** ![loisel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loisel/32/50626_2.png) [@loisel](https://discourse.julialang.org/u/loisel)\
**Post date:** [September 23, 2018, 9:07am UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/7 "2018-09-23T09:07:27Z")

</div>

Sorry, I may have been too vague. I was referring to this:

[https://github.com/JuliaLang/julia/issues/12447](https://github.com/JuliaLang/julia/issues/12447)

I was wondering whether that was still being planned, or abandoned?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 23, 2018, 11:57am UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/8 "2018-09-23T11:57:13Z")

</div>

Yes I know. That’s exactly what I’m referring to in my reply. It’s mostly an implementation detail/optimization and there’s almost nothing that’s not doable with the current implementation so it’s unclear what aspect is useful for you “for a thing”.

---

<div class="post-metadata">

**Author:** ![loisel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loisel/32/50626_2.png) [@loisel](https://discourse.julialang.org/u/loisel)\
**Post date:** [September 23, 2018, 12:17pm UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/9 "2018-09-23T12:17:03Z")

</div>

All right I see, I wasn’t aware of this reinterpret thing.

Thanks.

---

<div class="post-metadata">

**Author:** ![loisel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/loisel/32/50626_2.png) [@loisel](https://discourse.julialang.org/u/loisel)\
**Post date:** [June 6, 2024, 1:16pm UTC](https://discourse.julialang.org/t/memory-buffer-type/15345/10 "2024-06-06T13:16:54Z")

</div>

[Aha!](https://github.com/JuliaLang/julia/pull/51319)

Edit: `Memory{T}` will be in v1.11.
