# Automatic resizing of struct internal array when value changes?

**URL:** <https://discourse.julialang.org/t/automatic-resizing-of-struct-internal-array-when-value-changes/93790>\
**Category:** Performance\
**Created:** [January 30, 2023, 8:26pm UTC](https://discourse.julialang.org/t/automatic-resizing-of-struct-internal-array-when-value-changes/93790 "2023-01-30T20:26:38Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [January 30, 2023, 8:42pm UTC](https://discourse.julialang.org/t/automatic-resizing-of-struct-internal-array-when-value-changes/93790/4 "2023-01-30T20:42:01Z")

</div>

Both `getproperty` and `setproperty!` are kind of fiddly to get right, since they inherently rely on constant propagation of the accessed field for their type stability. You can write what you want to achieve like this:

```julia
function Base.setproperty!(ts::TheStruct, s::Symbol, v)
    if s === :N
        setfield!(ts, s, v) 
        arr = getfield(ts, :x) 
        resize!(arr, v)
    else
        setfield!(ts, s, v) 
    end
end

```

There’s probably a race condition here in multithreaded code. If I may ask, what are you trying to learn about using this?

---

_[View the full topic](https://discourse.julialang.org/t/automatic-resizing-of-struct-internal-array-when-value-changes/93790)._
