# Memory allocation while using @views

**URL:** <https://discourse.julialang.org/t/memory-allocation-while-using-views/66482>\
**Category:** Performance\
**Tags:** performance, arrays\
**Created:** [August 16, 2021, 1:01pm UTC](https://discourse.julialang.org/t/memory-allocation-while-using-views/66482 "2021-08-16T13:01:23Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [August 16, 2021, 1:40pm UTC](https://discourse.julialang.org/t/memory-allocation-while-using-views/66482/3 "2021-08-16T13:40:29Z")

</div>

I don’t think `@views` makes the LHS of an assignment like `+=` into a view:

```julia
 @macroexpand @views a[:] += b[:]

:(let var"##a#296" = a, var"##i#297" = (:)
      var"##a#296"[var"##i#297"] = (Base.maybeview)(var"##a#296", var"##i#297") + (Base.maybeview)(b, :)
  end)

```

> <https://github.com/JuliaLang/julia/pull/20164>
>
> This PR provides an \`@views\` macro that you can apply to a whole block of code (…e.g. a whole function definition) to convert \*every\* array-slicing operation into a view. Scalar indexing is not affected.
> 
> This allows you to opt-in to slices=views with minimal effort, a lot easier than adding \`@view\` or calls to \`view\` everywhere. This is especially easier for updating operations like \`.+=\`, where you can't put \`view\` on the left-hand side (as discussed \[on discourse\](https://discourse.julialang.org/t/is-there-a-way-to-choose-the-indices-for-broadcasting/1317)).

> This is especially easier for updating operations like `.+=` , where you can’t put `view` on the left-hand side (as discussed [on discourse](https://discourse.julialang.org/t/is-there-a-way-to-choose-the-indices-for-broadcasting/1317)).

---

_[View the full topic](https://discourse.julialang.org/t/memory-allocation-while-using-views/66482)._
