# Undef for non-arrays

**URL:** https://discourse.julialang.org/t/undef-for-non-arrays/69250
**Category:** General Usage
**Created:** [October 5, 2021, 6:48pm UTC](https://discourse.julialang.org/t/undef-for-non-arrays/69250 "2021-10-05T18:48:32Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [October 5, 2021, 6:48pm UTC](https://discourse.julialang.org/t/undef-for-non-arrays/69250/1 "2021-10-05T18:48:32Z")

</div>

Do we have something similar to undef for non-arrays? Wishful thinking:

```julia
f() = a::Tuple{Int, Int} where T = 5, undef 

```

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [October 5, 2021, 7:08pm UTC](https://discourse.julialang.org/t/undef-for-non-arrays/69250/2 "2021-10-05T19:08:08Z")

</div>

Could you explain what you want that to do?

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [October 5, 2021, 7:16pm UTC](https://discourse.julialang.org/t/undef-for-non-arrays/69250/3 "2021-10-05T19:16:20Z")

</div>

I’m trying to implement node allocators, which could make use of undefined memory like arrays do.

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [October 5, 2021, 7:21pm UTC](https://discourse.julialang.org/t/undef-for-non-arrays/69250/4 "2021-10-05T19:21:16Z")

</div>

You could use a `Ref`, e.g. `Ref{Tuple{Int, Int}}()` will be a mutable container that can be updated later.

Or you could use StaticArrays.jl’s `MVector`. e.g. `MVector{2, Int}(undef)`.

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [October 5, 2021, 7:39pm UTC](https://discourse.julialang.org/t/undef-for-non-arrays/69250/5 "2021-10-05T19:39:34Z")

</div>

`Ref{Tuple{Int, Int}}()` I understand, but if we have a vector of these there a probably some allocations required.

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [October 5, 2021, 8:01pm UTC](https://discourse.julialang.org/t/undef-for-non-arrays/69250/6 "2021-10-05T20:01:30Z")

</div>

If you have a vector of them then you just use `undef`.

```julia
julia> v = Vector{Tuple{Int, Int}}(undef, 2)
2-element Vector{Tuple{Int64, Int64}}:
 (9, 4)
 (11, 5)

```

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [October 10, 2021, 3:15pm UTC](https://discourse.julialang.org/t/undef-for-non-arrays/69250/7 "2021-10-10T15:15:51Z")

</div>

Just noticed [Create a struct with uninitialized fields - #5 by dfdx](https://discourse.julialang.org/t/create-a-struct-with-uninitialized-fields/6967/5) in the feed.
