# Non-allocating loop over a set of structs

**URL:** <https://discourse.julialang.org/t/non-allocating-loop-over-a-set-of-structs/25643>\
**Category:** Performance\
**Created:** [June 25, 2019, 10:17am UTC](https://discourse.julialang.org/t/non-allocating-loop-over-a-set-of-structs/25643 "2019-06-25T10:17:56Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [June 25, 2019, 3:22pm UTC](https://discourse.julialang.org/t/non-allocating-loop-over-a-set-of-structs/25643/14 "2019-06-25T15:22:42Z")

</div>

It looks like in this case the number of objects is small, so a tuple-based approach is probably best. Just wanted to note that in the case that the number of objects is large, but the number of different types is a lot smaller, you can use a tuple of concretely typed `Vector`s, unroll the loop over the different vectors, but then iterate over each of the vectors as normal. This approach is automated in [TypeSortedCollections.jl](https://github.com/tkoolen/TypeSortedCollections.jl) (I’m the main author). See also [Looping over different types with common behavior - #5 by tkoolen](https://discourse.julialang.org/t/looping-over-different-types-with-common-behavior/12068/5).

---

_[View the full topic](https://discourse.julialang.org/t/non-allocating-loop-over-a-set-of-structs/25643)._
