# Why A\[:,1\] .= x allocates?

**URL:** <https://discourse.julialang.org/t/why-a-1-x-allocates/31534>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 26, 2019, 3:04pm UTC](https://discourse.julialang.org/t/why-a-1-x-allocates/31534 "2019-11-26T15:04:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [November 26, 2019, 3:04pm UTC](https://discourse.julialang.org/t/why-a-1-x-allocates/31534/1 "2019-11-26T15:04:57Z")

</div>

Why the following code allocates?

```julia
function f(A,x) 
    A[:,1] .= x;
    return nothing
end

julia> A = randn(5,5); x = randn(5);

julia> @btime f($A, $x)
  30.941 ns (1 allocation: 48 bytes)

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 26, 2019, 4:18pm UTC](https://discourse.julialang.org/t/why-a-1-x-allocates/31534/2 "2019-11-26T16:18:28Z")

</div>

Because it is passing around a view and currently objects with pointers (like a `view`) needs to be allocated on the heap unless they can be proven to not escape which right now requires all uses to be inlined (although maybe changing soon, [https://github.com/JuliaLang/julia/pull/33886](https://github.com/JuliaLang/julia/pull/33886)).
