# Question about internal representation of Union{Missing, Float64}

**URL:** https://discourse.julialang.org/t/question-about-internal-representation-of-union-missing-float64/17000
**Category:** Performance
**Tags:** question, array, memory
**Created:** [October 31, 2018, 10:01am UTC](https://discourse.julialang.org/t/question-about-internal-representation-of-union-missing-float64/17000 "2018-10-31T10:01:19Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Maurizio\_Tomasi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maurizio_tomasi/32/384_2.png) [@Maurizio\_Tomasi](https://discourse.julialang.org/u/Maurizio_Tomasi)
#### Post date: [October 31, 2018, 10:01am UTC](https://discourse.julialang.org/t/question-about-internal-representation-of-union-missing-float64/17000/1 "2018-10-31T10:01:19Z")

</div>

I am trying to understand the internals of the datatype `Union{Missing, Float64}`. From what I understand, this type encodes the presence of elements in the array by means of a hidden `Array{UInt8}`, which flags which elements are present and which are not.

I tried to determine if this was true using `sizeof`, but I found an unexpected result:

```julia
julia> x = [3.0, 4.0, 5.0]
3-element Array{Float64,1}:
 3.0
 4.0
 5.0

julia> y = [3.0, missing, 5.0]
3-element Array{Union{Missing, Float64},1}:
 3.0     
  missing
 5.0     

julia> sizeof(x), sizeof(y)
(24, 24)

```

I don’t understand why is `sizeof` reporting the same size for `x` and `y`, I would have expected 24 bytes for `x` and 27 (24 + 3) for `y`.

May somebody explain what’s going on? Perhaps `sizeof` is not the right way to measure the amount of allocated memory for union types?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [October 31, 2018, 11:07am UTC](https://discourse.julialang.org/t/question-about-internal-representation-of-union-missing-float64/17000/2 "2018-10-31T11:07:57Z")

</div>

cf

> [@sizeof(::Vector{Union{missing,T}}), and hypothetical size](https://discourse.julialang.org/t/sizeof-vector-union-missing-t-and-hypothetical-size/15271):
>
> Two (related) questions: julia\> sizeof(vcat(ones(10), fill(missing, 10))) 160 but I expected 20\*9 because of the type tag, what am I missing? v"1.1.0-DEV.298". If I have a type T which is a Union, can I calculate the size of a Vector{T} of n elements without actually creating one?

---

<div class="post-metadata">

### Author: ![Maurizio\_Tomasi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maurizio_tomasi/32/384_2.png) [@Maurizio\_Tomasi](https://discourse.julialang.org/u/Maurizio_Tomasi)
#### Post date: [October 31, 2018, 3:46pm UTC](https://discourse.julialang.org/t/question-about-internal-representation-of-union-missing-float64/17000/3 "2018-10-31T15:46:17Z")

</div>

Thanks a lot! From that thread I learned that the test should use `Base.summarysize` instead of `sizeof`:

```julia
julia> Base.summarysize([3.0, missing, 5.0])
80

julia> Base.summarysize([3.0, 4.0, 5.0])
64

```
