# Specifying size of vector in a struct

**URL:** <https://discourse.julialang.org/t/specifying-size-of-vector-in-a-struct/94125>\
**Category:** General Usage\
**Tags:** struct\
**Created:** [February 6, 2023, 8:51am UTC](https://discourse.julialang.org/t/specifying-size-of-vector-in-a-struct/94125 "2023-02-06T08:51:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![udax](https://avatars.discourse-cdn.com/v4/letter/u/a587f6/32.png) [@udax](https://discourse.julialang.org/u/udax)\
**Post date:** [February 6, 2023, 8:51am UTC](https://discourse.julialang.org/t/specifying-size-of-vector-in-a-struct/94125/1 "2023-02-06T08:51:23Z")

</div>

I have a struct like so:

```julia
struct rpoint
    pn::Int64 #patch number
    xyz::Vector{Float64} #coordinates
 end 

```

Note: the xyz field will always be populated with a vector of size 3. I have two questions:

1. Is it true that not specifying the size of the vector can lead to sub-par performance? When I profiled my code, I got a bunch of red “runtime-dispatch” flags, which I’m trying to track down. Can the above cause it?
2. How would I specify the size of the vector in the struct?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [February 6, 2023, 9:04am UTC](https://discourse.julialang.org/t/specifying-size-of-vector-in-a-struct/94125/2 "2023-02-06T09:04:04Z")

</div>

1. Does not seem likely to be the cause.
2. Switch from `Vector` to a type from the [StaticArrays](https://github.com/JuliaArrays/StaticArrays.jl) package.

---

<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:** [February 6, 2023, 9:06am UTC](https://discourse.julialang.org/t/specifying-size-of-vector-in-a-struct/94125/3 "2023-02-06T09:06:50Z")

</div>

> [@udax](#):
>
> Is it true that not specifying the size of the vector can lead to sub-par performance?

Yes, but here you may be confusing with not specifying the dimensions of an Array, which is what would give you run time dispatch problems (type instability in general). It likely that your red flags come from something else.

> [@udax](#):
>
> How would I specify the size of the vector in the struct?

Here the standard and best option is to use `SVector` from the StaticArrays package.
