# Help with allocations (variable length least squares)

**URL:** <https://discourse.julialang.org/t/help-with-allocations-variable-length-least-squares/57931>\
**Category:** New to Julia\
**Tags:** memory-allocation\
**Created:** [March 25, 2021, 1:53pm UTC](https://discourse.julialang.org/t/help-with-allocations-variable-length-least-squares/57931 "2021-03-25T13:53:05Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 25, 2021, 5:25pm UTC](https://discourse.julialang.org/t/help-with-allocations-variable-length-least-squares/57931/6 "2021-03-25T17:25:06Z")

</div>

> [@Ribeiro](#):
>
> I don’t really understand the advantage of MArrays, to be honest

They can be stack allocated and mutated, for example:

```julia
julia> using StaticArrays, BenchmarkTools

julia> function rotate!(v)
         M = MMatrix{2,2,Float64}(0,0,0,0)
         for i in 1:length(v)
            θ = 2π*rand()
            M[1,1] = cos(θ)
            M[1,2] = -sin(θ)
            M[2,1] = sin(θ)
            M[2,2] = cos(θ)
            v[i] = M*v[i]
         end
       end
rotate! (generic function with 2 methods)

julia> v = [rand(SVector{2,Float64}) for i in 1:10];

julia> @btime rotate!($v)
  408.805 ns (0 allocations: 0 bytes)

```

---

_[View the full topic](https://discourse.julialang.org/t/help-with-allocations-variable-length-least-squares/57931)._
