# Behavior of vector fields in mutable structures

**URL:** <https://discourse.julialang.org/t/behavior-of-vector-fields-in-mutable-structures/12583>\
**Category:** New to Julia\
**Created:** [July 22, 2018, 2:17pm UTC](https://discourse.julialang.org/t/behavior-of-vector-fields-in-mutable-structures/12583 "2018-07-22T14:17:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [July 22, 2018, 2:43pm UTC](https://discourse.julialang.org/t/behavior-of-vector-fields-in-mutable-structures/12583/2 "2018-07-22T14:43:07Z")

</div>

Yes, this is how julia works. After you do

```julia
x = [1, 2]
Sa = S(x)

```

`x` and `Sa.f` are the same vector in that they occupy the same physical memory. See also [this post](https://discourse.julialang.org/t/converting-a-matlab-code-into-julia/12166/18) for an explanation of this (you can think of `A` and `B` in that post as your `x` and `S.f`).  
If you want your type `S` to make a copy of the input you can define an inner constructor that copies:

```julia
mutable struct S
    f::Vector{Int}
    S(x) = new(copy(x))
end

```

---

_[View the full topic](https://discourse.julialang.org/t/behavior-of-vector-fields-in-mutable-structures/12583)._
