# Allocation during construction of compile-time sized structure

**URL:** <https://discourse.julialang.org/t/allocation-during-construction-of-compile-time-sized-structure/87435>\
**Category:** Performance\
**Tags:** staticarrays\
**Created:** [September 18, 2022, 12:13pm UTC](https://discourse.julialang.org/t/allocation-during-construction-of-compile-time-sized-structure/87435 "2022-09-18T12:13:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)\
**Post date:** [September 18, 2022, 12:13pm UTC](https://discourse.julialang.org/t/allocation-during-construction-of-compile-time-sized-structure/87435/1 "2022-09-18T12:13:23Z")

</div>

I have a simple, immutable structure that wraps a statically sized matrix. When I construct it with an initialization value, it causes a memory allocation. I expected there to be no such allocation. Should there be an allocation, or is this an issue with the compiler? Here is the MWE:

```julia
using BenchmarkTools
using StaticArrays

struct MyMat
    m::SMatrix{3, 3, Float64}
end

function test()
    A = @SMatrix randn(3, 3)
    @btime B = MyMat($A)
end

test();

```

> 4.750 ns (1 allocation: 80 bytes)

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [September 18, 2022, 12:25pm UTC](https://discourse.julialang.org/t/allocation-during-construction-of-compile-time-sized-structure/87435/2 "2022-09-18T12:25:04Z")

</div>

The SMatrix type needs a fourth type parameter (which is redundant):

> [@user664303](#):
>
> ```julia
> struct MyMat
> m::SMatrix{3, 3, Float64, 9}
> end
> 
> ```
