The easiest way usually to figure this out is just to enter ?Ref
in the REPL:
help?> Ref
search: Ref WeakRef prevfloat UndefRefError GlobalRef uppercasefirst lowercasefirst ProcessFailedException
Ref{T}
An object that safely references data of type T. This type is guaranteed to point to valid, Julia-allocated
memory of the correct type. The underlying data is protected from freeing by the garbage collector as long as
the Ref itself is referenced.
In Julia, Ref objects are dereferenced (loaded or stored) with [].
Creation of a Ref to a value x of type T is usually written Ref(x). Additionally, for creating interior pointers
to containers (such as Array or Ptr), it can be written Ref(a, i) for creating a reference to the i-th element
of a.
When passed as a ccall argument (either as a Ptr or Ref type), a Ref object will be converted to a native
pointer to the data it references.
There is no invalid (NULL) Ref in Julia, but a C_NULL instance of Ptr can be passed to a ccall Ref argument.
Use in broadcasting
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
Ref is sometimes used in broadcasting in order to treat the referenced values as a scalar:
julia> isa.(Ref([1,2,3]), [Array, Dict, Int])
3-element BitArray{1}:
1
0
0
It even explains, why Ref
would be used in broadcasting.