# Upper limit for size of static array

**URL:** <https://discourse.julialang.org/t/upper-limit-for-size-of-static-array/12069>\
**Category:** General Usage\
**Tags:** package\
**Created:** [June 29, 2018, 3:32pm UTC](https://discourse.julialang.org/t/upper-limit-for-size-of-static-array/12069 "2018-06-29T15:32:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shipengcheng1230](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shipengcheng1230/32/4089_2.png) [@shipengcheng1230](https://discourse.julialang.org/u/shipengcheng1230)\
**Post date:** [June 29, 2018, 3:32pm UTC](https://discourse.julialang.org/t/upper-limit-for-size-of-static-array/12069/1 "2018-06-29T15:32:47Z")

</div>

Hello, I tried to allocate large static arrays but failed as shown below. Is there a way to find out the upper limits? I couldn’t find related information around.

```julia-repl
julia> using StaticArrays

julia> @SMatrix zeros(16, 16)
16×16 StaticArrays.SArray{Tuple{16,16},Float64,2,256}:
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

julia> @SMatrix zeros(160, 160)
ERROR: syntax: invalid syntax (memory-error out of gc handles)
Stacktrace:
 [1] Type(...) at /Users/spc/.julia/v0.6/StaticArrays/src/SMatrix.jl:33
 [2] macro expansion at /Users/spc/.julia/v0.6/StaticArrays/src/arraymath.jl:11 [inlined]
 [3] _zeros at /Users/spc/.julia/v0.6/StaticArrays/src/arraymath.jl:4 [inlined]
 [4] zeros(::Type{StaticArrays.SArray{Tuple{160,160},T,2,L} where L where T}) at /Users/spc/.julia/v0.6/StaticArrays/src/arraymath.jl:2

julia> @SMatrix zeros(1600, 1600)
ERROR: syntax: expression too large
Stacktrace:
 [1] zeros(::Type{StaticArrays.SArray{Tuple{1600,1600},T,2,L} where L where T}) at /Users/spc/.julia/v0.6/StaticArrays/src/arraymath.jl:2

```

---

<div class="post-metadata">

**Author:** ![js135005](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/js135005/32/8219_2.png) [@js135005](https://discourse.julialang.org/u/js135005)\
**Post date:** [June 29, 2018, 3:37pm UTC](https://discourse.julialang.org/t/upper-limit-for-size-of-static-array/12069/2 "2018-06-29T15:37:54Z")

</div>

IIRC the StaticArrays documentation says you shouldn’t use it for arrays larger than 100x100.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [June 29, 2018, 3:43pm UTC](https://discourse.julialang.org/t/upper-limit-for-size-of-static-array/12069/3 "2018-06-29T15:43:35Z")

</div>

This upper limit was due to being built on tuples, and the inference restriction on tuple size was removed in Julia v0.7:

[https://github.com/JuliaLang/julia/pull/27398](https://github.com/JuliaLang/julia/pull/27398)

That said, using static arrays shouldn’t be done for arbitrarily large arrays since using the stack and optimizing directly on the size tends to not work so well for big arrays, but the removal of the arbitrary size limit should help the “largest size for which static arrays are useful” get a good bump to a higher number.
