# Accessing array element: splatting VS explicit writing them out

**URL:** https://discourse.julialang.org/t/accessing-array-element-splatting-vs-explicit-writing-them-out/64973
**Category:** New to Julia
**Tags:** performance, array
**Created:** [July 20, 2021, 9:14am UTC](https://discourse.julialang.org/t/accessing-array-element-splatting-vs-explicit-writing-them-out/64973 "2021-07-20T09:14:15Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [July 21, 2021, 2:34am UTC](https://discourse.julialang.org/t/accessing-array-element-splatting-vs-explicit-writing-them-out/64973/4 "2021-07-21T02:34:56Z")

</div>

> [@pmlo](#):
>
> ` mvup!(xvec, d) = xvec[d] == N ? xvec[d] = 1 : xvec[d] += 1`

A much more flexible method to implement periodic boundary conditions (which I guess is what you are doing) is to use “ghost cells”. See e.g. [Finite difference Laplacian with five-point stencil - #2 by stevengj](https://discourse.julialang.org/t/finite-difference-laplacian-with-five-point-stencil/25014/2)

> [@pmlo](#):
>
> `x = [i1, i2, i3]`

This is allocating a new array on every loop iteration, which will be slow. I second the suggestion to use `CartesianIndices` here — that’s what they are for. (You could also use StaticArrays.jl). See [Base.Cartesian · The Julia Language](https://docs.julialang.org/en/v1/devdocs/cartesian/#Base.Cartesian)

---

_[View the full topic](https://discourse.julialang.org/t/accessing-array-element-splatting-vs-explicit-writing-them-out/64973)._
