# Why making \`a\[range\] = b\[range\]\` seems to make unnecessary allocations?

**URL:** <https://discourse.julialang.org/t/why-making-a-range-b-range-seems-to-make-unnecessary-allocations/29325>\
**Category:** Performance\
**Created:** [September 30, 2019, 2:20pm UTC](https://discourse.julialang.org/t/why-making-a-range-b-range-seems-to-make-unnecessary-allocations/29325 "2019-09-30T14:20:20Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [September 30, 2019, 2:57pm UTC](https://discourse.julialang.org/t/why-making-a-range-b-range-seems-to-make-unnecessary-allocations/29325/3 "2019-09-30T14:57:14Z")

</div>

> [@pedrohnv](#):
>
> b[1:n, 1:n]

Slicing an array in Julia creates a copy, which is where your allocations are coming from. You can do `@view(b[1:n, 1:n])` to create a view instead, which will avoid the unnecessary copy. See [Could you explain what are views? - #3 by stevengj](https://discourse.julialang.org/t/could-you-explain-what-are-views/17535/3) for some more explanation.

---

_[View the full topic](https://discourse.julialang.org/t/why-making-a-range-b-range-seems-to-make-unnecessary-allocations/29325)._
