# Managing temporaries

**URL:** <https://discourse.julialang.org/t/managing-temporaries/78890>\
**Category:** General Usage\
**Tags:** performance, array\
**Created:** [April 1, 2022, 11:12pm UTC](https://discourse.julialang.org/t/managing-temporaries/78890 "2022-04-01T23:12:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [April 1, 2022, 11:12pm UTC](https://discourse.julialang.org/t/managing-temporaries/78890/1 "2022-04-01T23:12:37Z")

</div>

I’ve been told that C++ can now manage temporary matrices in loops automatically. For instance,

```julia
for (...) {
      // create B, D
      K += B' * D * B * Jw
}

```

would apparently allocate temporaries only once, before the loop starts.

If this is actually true, what are the chances Julia will have something similar?

---

<div class="post-metadata">

**Author:** ![Egwene\_al\_Vere](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@Egwene\_al\_Vere](https://discourse.julialang.org/u/Egwene_al_Vere)\
**Post date:** [April 2, 2022, 1:26am UTC](https://discourse.julialang.org/t/managing-temporaries/78890/2 "2022-04-02T01:26:42Z")

</div>

There is [AutoPreallocation.jl](https://github.com/oxinabox/AutoPreallocation.jl), [Alloc.jl](https://github.com/FluxML/Alloc.jl) and [PreallocationTools](https://github.com/SciML/PreallocationTools.jl) for helping writing non-allocating function/loops, although development for the first 2 has slowed down a bit (most recent commits in 2020). Would be nice to see it in the main language though. For use with differential equations, the ModelingToolkit.jl may also help with allocations somewhat automatically
