# Counterintuitive array update allocations

**URL:** <https://discourse.julialang.org/t/counterintuitive-array-update-allocations/63490>\
**Category:** Performance\
**Created:** [June 24, 2021, 9:04am UTC](https://discourse.julialang.org/t/counterintuitive-array-update-allocations/63490 "2021-06-24T09:04:48Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Seif\_Shebl](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Post date:** [July 15, 2021, 3:44pm UTC](https://discourse.julialang.org/t/counterintuitive-array-update-allocations/63490/7 "2021-07-15T15:44:11Z")

</div>

I don’t know what your real application is, but if the indices array `Part` is that simple, you could use a simpler and much faster version as `update4!` below. You don’t need to use `Part` at all in this case.

```julia
function update4!(A_field, A)
   for i in eachindex(A)
       @views A_field[2i-1:2i] = A[i]
   end
end

N = 10
shapeA = (N, N)
Part = [[i, i+1] for i in 1:2:prod(shapeA)]
A = [rand(length(J)) for J in Part]
A_field = zeros(shapeA)

@btime update4!(y, $A) setup = (y = copy(A_field))
  218.200 ns (0 allocations: 0 bytes)

```

---

_[View the full topic](https://discourse.julialang.org/t/counterintuitive-array-update-allocations/63490)._
