# Is there a way to avoid allocating memory when using Chain.jl or pipeing? Technica

**URL:** <https://discourse.julialang.org/t/is-there-a-way-to-avoid-allocating-memory-when-using-chain-jl-or-pipeing-technica/57206>\
**Category:** General Usage\
**Created:** [March 15, 2021, 3:35pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-avoid-allocating-memory-when-using-chain-jl-or-pipeing-technica/57206 "2021-03-15T15:35:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [March 15, 2021, 3:35pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-avoid-allocating-memory-when-using-chain-jl-or-pipeing-technica/57206/1 "2021-03-15T15:35:38Z")

</div>

Is there a way to avoid allocating memory when using Chain.jl or pipeing? Technically these are type stable and can mutate the original array to avoid allocation

```julia
julia&gt; @time @chain x begin
           _ * 1
       end;
  0.002212 seconds (2 allocations: 7.629 MiB)

julia&gt; @time @chain x begin
           _ * 1
           _ * 1
       end;
  0.008802 seconds (4 allocations: 15.259 MiB)

```

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1615822384158900?thread_ts=1615822384.158900&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [March 16, 2021, 12:11pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-avoid-allocating-memory-when-using-chain-jl-or-pipeing-technica/57206/2 "2021-03-16T12:11:36Z")

</div>

You could use `rmul!` to overwrite the chained array

[Linear Algebra · The Julia Language](https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/#LinearAlgebra.rmul)!

```julia
@chain x begin
    rmul!(2)
end

```

Or overwrite it like this I guess. At some point you loose the benefit of chaining syntax for stuff like this

```julia
@chain x begin
   _ .*= 1
end

```
