# Allocation in broadcasting of round for staticarrays

**URL:** <https://discourse.julialang.org/t/allocation-in-broadcasting-of-round-for-staticarrays/76143>\
**Category:** General Usage\
**Tags:** memory-allocation, staticarrays\
**Created:** [February 10, 2022, 5:28am UTC](https://discourse.julialang.org/t/allocation-in-broadcasting-of-round-for-staticarrays/76143 "2022-02-10T05:28:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jae-Mo\_Lihm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jae-mo_lihm/32/20145_2.png) [@Jae-Mo\_Lihm](https://discourse.julialang.org/u/Jae-Mo_Lihm)\
**Post date:** [February 10, 2022, 5:28am UTC](https://discourse.julialang.org/t/allocation-in-broadcasting-of-round-for-staticarrays/76143/1 "2022-02-10T05:28:23Z")

</div>

Why does the `round.(Int, x::SVector)` allocate?

```julia
using BenchmarkTools, StaticArrays
x = SVector{2}([0., 1.])

@btime round.(Int, $x) # 21.180 ns (1 allocation: 16 bytes)
@btime round.(Int, $(x.data)) # 6.451 ns (0 allocations: 0 bytes)

```

```julia
julia> versioninfo()
Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, haswell)
Environment:
  JULIA = /home/jmlim/appl/julia-1.7.0/bin/julia

(@v1.7) pkg> status StaticArrays
      Status `~/.julia/environments/v1.7/Project.toml`
  [90137ffa] StaticArrays v1.2.13

```

and also with ` StaticArrays v1.3.4`

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [February 10, 2022, 8:37am UTC](https://discourse.julialang.org/t/allocation-in-broadcasting-of-round-for-staticarrays/76143/2 "2022-02-10T08:37:00Z")

</div>

I’m seeing the same thing. Odd.

BTW, this

> [@Jae-Mo\_Lihm](#):
>
> `x = SVector{2}([0., 1.])`

creates a regular `Vector` which is then converted to an `SVector`, so that’s an additional allocation. Instead, just create the `SVector` directly, like one of these:

```julia
SVector{2}(0.0, 1.0)
SVector(0.0, 1.0) # the {2} isn't necessary
SA[0.0, 1.0]

```

Doesn’t help with the other allocation, though.

---

<div class="post-metadata">

**Author:** ![Jae-Mo\_Lihm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jae-mo_lihm/32/20145_2.png) [@Jae-Mo\_Lihm](https://discourse.julialang.org/u/Jae-Mo_Lihm)\
**Post date:** [February 10, 2022, 8:55am UTC](https://discourse.julialang.org/t/allocation-in-broadcasting-of-round-for-staticarrays/76143/3 "2022-02-10T08:55:02Z")

</div>

I opened an issue: [https://github.com/JuliaArrays/StaticArrays.jl/issues/992](https://github.com/JuliaArrays/StaticArrays.jl/issues/992)

---

<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:** [February 10, 2022, 11:36am UTC](https://discourse.julialang.org/t/allocation-in-broadcasting-of-round-for-staticarrays/76143/4 "2022-02-10T11:36:51Z")

</div>

Here this is a regression relative to 1.6.3, where that didn’t allocate. I commented on the issue.
