# Constructor to delay array allocation in mutable struct

**URL:** <https://discourse.julialang.org/t/constructor-to-delay-array-allocation-in-mutable-struct/48574>\
**Category:** General Usage\
**Tags:** memory-allocation, mutable-structure\
**Created:** [October 18, 2020, 5:33am UTC](https://discourse.julialang.org/t/constructor-to-delay-array-allocation-in-mutable-struct/48574 "2020-10-18T05:33:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [October 18, 2020, 5:33am UTC](https://discourse.julialang.org/t/constructor-to-delay-array-allocation-in-mutable-struct/48574/1 "2020-10-18T05:33:44Z")

</div>

Hi,

I wish to define a mutable structure containing - among other things - an array

```julia
mutable struct MyType
      values :: Matrix{Float} # stands for arbitrary Array of arbitrary data
end

```

I then wish to create a variable of this type _without allocating the Array_ because I do not yet know what length it will be. To this effect, I should define a constructor

```julia
MyType() = MyType(???)

```

The ??? stands for “how do I tell Julia to wait 'til I’m good and ready to allocate an array”. `[]` works if my array is a Vector, but not otherwise (and for all I know could be giving work to the GC)

🙂

Philippe

---

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [October 18, 2020, 5:40am UTC](https://discourse.julialang.org/t/constructor-to-delay-array-allocation-in-mutable-struct/48574/2 "2020-10-18T05:40:54Z")

</div>

I think you need so called incomplete initialization

[https://docs.julialang.org/en/v1/manual/constructors/#Incomplete-Initialization](https://docs.julialang.org/en/v1/manual/constructors/#Incomplete-Initialization)

---

<div class="post-metadata">

**Author:** ![Philippe\_Maincon1](https://avatars.discourse-cdn.com/v4/letter/p/ec9cab/32.png) [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Post date:** [October 18, 2020, 6:28am UTC](https://discourse.julialang.org/t/constructor-to-delay-array-allocation-in-mutable-struct/48574/3 "2020-10-18T06:28:55Z")

</div>

Bingo!

Thank you!

```julia
mutable struct MyType
      values :: Matrix{Float} # stands for arbitrary Array of arbitrary data
      MyType() = new()
end
obj = MyType()

```
