# Increase in allocations with Julia v1.11-beta

**URL:** <https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838>\
**Category:** Internals & Design\
**Tags:** performance, arrays\
**Created:** [April 11, 2024, 2:19pm UTC](https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838 "2024-04-11T14:19:59Z")\
**Posts on this page:** 7\
**Page:** 3

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [May 7, 2024, 12:18am UTC](https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838/41 "2024-05-07T00:18:11Z")

</div>

Release notes are not feature frozen until the release. If there’s something that needs release notes or docs, we should add those.

`A.ref.mem`

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [May 7, 2024, 6:44am UTC](https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838/42 "2024-05-07T06:44:24Z")

</div>

> [@Oscar\_Smith](#):
>
> A.ref.mem

Are you saying this is supported? Given that the `ref` field isn’t documented AFAIK, I’d think that even `A.ref` is not a valid thing to do for users who expect compatibility.

---

<div class="post-metadata">

**Author:** ![mikmoore](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mikmoore/32/31109_2.png) [@mikmoore](https://discourse.julialang.org/u/mikmoore)\
**Post date:** [May 7, 2024, 1:49pm UTC](https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838/43 "2024-05-07T13:49:17Z")

</div>

> [@nsajko](#):
>
> Are you saying this is supported?

I’m fairly sure that the backing `Memory` is internal also and even the fact that it’s backed my `Memory` is an implementation detail. Especially for `Array{<:Any,1}`, since the `Memory` may be reallocated. So once you’re asking for it, you’re already beyond the public interface.

Although there may still be value in a internal function for this purpose. I don’t know. `A.ref.mem` seems simple enough and, if it ever breaks in some future version, it will probably break loudly (so you’ll notice it and it will be easy to fix). Whereas an accessor function, even an internal one, carries some implication of forward support.

---

<div class="post-metadata">

**Author:** ![juthohaegeman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juthohaegeman/32/8620_2.png) [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)\
**Post date:** [May 8, 2024, 8:15am UTC](https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838/44 "2024-05-08T08:15:12Z")

</div>

My question was triggered by @mbauman 's suggestion that package developers may choose to use `Memory`, for example as the field of a custom type, if they do not need the full `Array` functionality (in particular the resizing property), but simply a block of memory of fixed size. `Memory` is definitely exported from Base, so its mere existence cannot be considered an internal implementation detail.

Actually, the documentation I am looking for is for the reverse operation. If I now want to return a normal `Array` which is constructed from (part of) a `Memory` object, what is the interface for doing so. Should I go via `Base.unsafe_wrap` using a `pointer` to my memory object, or can I directly create the `Array` from a `MemoryRef`?

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [May 8, 2024, 8:24am UTC](https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838/45 "2024-05-08T08:24:58Z")

</div>

> [@juthohaegeman](#):
>
> If I now want to return a normal `Array` which is constructed from (part of) a `Memory` object, what is the interface for doing so. Should I go via `Base.unsafe_wrap` using a `pointer` to my memory object, or can I directly create the `Array` from a `MemoryRef`?

```julia-repl
julia> m = Memory{Int}(undef, 1)
1-element Memory{Int64}:
 0

julia> a = @view m[1:1]
1-element Vector{Int64}:
 0

julia> a.ref.mem === m
true

```

---

<div class="post-metadata">

**Author:** ![juthohaegeman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juthohaegeman/32/8620_2.png) [@juthohaegeman](https://discourse.julialang.org/u/juthohaegeman)\
**Post date:** [May 8, 2024, 8:35am UTC](https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838/46 "2024-05-08T08:35:45Z")

</div>

Thanks. That is convenient indeed. Somehow I missed that.

While playing around, I also noticed that some behaviour from the Julep is not working, for example:

```julia
a = Memory{Float64}(undef, 100)
ref1 = Base.memoryref(a, 10) # error
# but the following indirect approach:
ref2 = Base.memoryref(a) # works fine
ref3 = Base.memoryref(ref2, 10) # works fine

```

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [May 8, 2024, 2:54pm UTC](https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838/47 "2024-05-08T14:54:58Z")

</div>

> [@juthohaegeman](#):
>
> My question was triggered by @mbauman 's suggestion that package developers may choose to use `Memory`

It’s funny, I was trying to _dissuade_ folks from using Memory.

> [@mbauman](#):
>
> No. Just use `Array`…

But we’re in #Internals & Design here — so discussions are especially blurry between internals and general usage. Memory is a new thing — and it replaces a bit of very deep magic with something that, yes, I do expect folks will start using more. But as you noticed, the docs are still nascent and can be improved. YMMV.

[Previous page](https://discourse.julialang.org/t/increase-in-allocations-with-julia-v1-11-beta/112838.md?page=2)
