# Ref{T} vs Base.RefValue{T}

**URL:** <https://discourse.julialang.org/t/ref-t-vs-base-refvalue-t/127886>\
**Category:** Performance\
**Created:** [April 9, 2025, 1:11pm UTC](https://discourse.julialang.org/t/ref-t-vs-base-refvalue-t/127886 "2025-04-09T13:11:04Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [April 10, 2025, 1:07pm UTC](https://discourse.julialang.org/t/ref-t-vs-base-refvalue-t/127886/21 "2025-04-10T13:07:07Z")

</div>

> [@jakobnissen](#):
>
> See [Export Base.RefValue · Issue #40369 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/40369) - apparenly, you might as well make the whole struct mutable.

That issue discussion appears to be completely beside the point?

`Base.RefValue` is basically the equivalent of `mutable struct GenericContainer{T} contents::T end`, with some slightly different extra sugar, broadcasting behavior, ccall behavior built in, and no ceremony.

Why would you put a Ref into an immutable struct? Obviously because your program logic wants to put references to the same shared mutable state into many different immutable structs, duh! Same reason why you would put any mutable struct into an immutable one.

That’s eminently sensible.

> [@Stephen\_Vavasis](#):
>
> I use `Array{T,0}` for this purpose.

You can do that, but it’s less efficient / eats more memory / has an extra allocation + pointer indirection.

[Previous page](https://discourse.julialang.org/t/ref-t-vs-base-refvalue-t/127886.md?page=1)
