# How to create an array of preallocated mutable structs

**URL:** https://discourse.julialang.org/t/how-to-create-an-array-of-preallocated-mutable-structs/18482
**Category:** New to Julia
**Created:** [December 9, 2018, 8:12am UTC](https://discourse.julialang.org/t/how-to-create-an-array-of-preallocated-mutable-structs/18482 "2018-12-09T08:12:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)
#### Post date: [December 9, 2018, 8:12am UTC](https://discourse.julialang.org/t/how-to-create-an-array-of-preallocated-mutable-structs/18482/1 "2018-12-09T08:12:05Z")

</div>

Let’s say I want to preallocate 100 `Point` objects in an array… how?

```julia
julia> mutable struct Point 
         x::Float64
         y::Float64
       end

```

The `fill` function come to mind but it does not work because only one `Point` is made and all 100 entries in the array point to the same object…

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [December 9, 2018, 8:18am UTC](https://discourse.julialang.org/t/how-to-create-an-array-of-preallocated-mutable-structs/18482/2 "2018-12-09T08:18:37Z")

</div>

Use an array comprehension:

```julia
[Point(x, y) for x in 1:4, y in 1:6]

```

---

<div class="post-metadata">

### Author: ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)
#### Post date: [December 9, 2018, 10:35am UTC](https://discourse.julialang.org/t/how-to-create-an-array-of-preallocated-mutable-structs/18482/3 "2018-12-09T10:35:42Z")

</div>

Alternatively:

```julia
Point.(1:4, (1:6)')

```

(I really like the dot-broadcast notation in Julia.)
