# Local arrays in for loops

**URL:** https://discourse.julialang.org/t/local-arrays-in-for-loops/56216
**Category:** New to Julia
**Created:** [February 28, 2021, 10:47pm UTC](https://discourse.julialang.org/t/local-arrays-in-for-loops/56216 "2021-02-28T22:47:48Z")
**Posts on this page:** 1
**Showing post:** 30

<div class="post-metadata">

### Author: ![Ribeiro](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@Ribeiro](https://discourse.julialang.org/u/Ribeiro)
#### Post date: [March 1, 2021, 7:27pm UTC](https://discourse.julialang.org/t/local-arrays-in-for-loops/56216/30 "2021-03-01T19:27:05Z")

</div>

I don’t really know what’s happening, but I can’t get it down to zero anymore. I can get it down to one by doing something really weird.

```julia
using StaticArrays
using LinearAlgebra
N=1000;
vertexList = Vector{StaticArrays.SVector{3,Float64}}(undef,N);
elements = Vector{StaticArrays.SVector{3,Int}}(undef,N);
for i in 1:1000
    vertexList[i] = SA_F64[rand(),rand(),rand()];
    elements[i] = SA[rand(1:N),rand(1:N),rand(1:N)];
end
elementLength = length(elements[1]);

function temp1(vertexList,elements)
    elementLength = length(elements[1]);
    acc = SA_F64[0,0,0];
    for k in 1:size(elements,1)
        vertices = vertexList[elements[k]];
        edges = @SVector [vertices[v%elementLength+1]-vertices[v] for v in 1:elementLength];
        edgesNorm = norm.(edges);
        acc += edgesNorm;
    end
    return acc;
end
@time temp1(vertexList,elements);

```

Note that it only works if `elementLength` is defined twice. Otherwise, I get 18k allocations.  
Is someone is able to explain this?

---

_[View the full topic](https://discourse.julialang.org/t/local-arrays-in-for-loops/56216)._
