# I want to write a better performance array, don't know if there is a ready-made one?

**URL:** https://discourse.julialang.org/t/i-want-to-write-a-better-performance-array-dont-know-if-there-is-a-ready-made-one/53317
**Category:** Performance
**Created:** [January 14, 2021, 2:52am UTC](https://discourse.julialang.org/t/i-want-to-write-a-better-performance-array-dont-know-if-there-is-a-ready-made-one/53317 "2021-01-14T02:52:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Zq\_F](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zq_f/32/20147_2.png) [@Zq\_F](https://discourse.julialang.org/u/Zq_F)
#### Post date: [January 14, 2021, 2:52am UTC](https://discourse.julialang.org/t/i-want-to-write-a-better-performance-array-dont-know-if-there-is-a-ready-made-one/53317/1 "2021-01-14T02:52:04Z")

</div>

I want to write a better performance array, don’t know if there is a ready-made one?

I wrote a prototype

struct Arr{T, N} \<: AbstractArray{T, N}  
ilength::Int64  
data::Array{T, N}  
end

Base.length(A::Arr) = A.ilength  
Base.empty!(A::Arr) =A.ilength=0  
Base.push!(A::Arr,x)=(A.data[A.ilength+1]=x;A.ilength+=1)

This array does not empty the data when empty! is executed, but ilength=0, which avoids memory allocation, so the speed should be faster

No memory allocation is required when executing push!

I think someone has written such an array, but I didn’t find a ready-made one. I hope someone can tell, thank you

I took a look at StaticArrays, but he recommends no more than 100 elements

---

<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: [January 14, 2021, 3:08am UTC](https://discourse.julialang.org/t/i-want-to-write-a-better-performance-array-dont-know-if-there-is-a-ready-made-one/53317/2 "2021-01-14T03:08:41Z")

</div>

> [@Zq\_F](#):
>
> This array does not empty the data when `empty!` is executed, but `ilength=0`, which avoids memory allocation, so the speed should be faster. No memory allocation is required when executing `push!`

The built-in `Array` type already does this if you use `sizehint!`.

---

<div class="post-metadata">

### Author: ![Zq\_F](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zq_f/32/20147_2.png) [@Zq\_F](https://discourse.julialang.org/u/Zq_F)
#### Post date: [January 14, 2021, 3:30am UTC](https://discourse.julialang.org/t/i-want-to-write-a-better-performance-array-dont-know-if-there-is-a-ready-made-one/53317/3 "2021-01-14T03:30:32Z")

</div>

I found PushVectors, the code is almost the same as my idea, thanks for your hint!

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [January 14, 2021, 4:06am UTC](https://discourse.julialang.org/t/i-want-to-write-a-better-performance-array-dont-know-if-there-is-a-ready-made-one/53317/4 "2021-01-14T04:06:10Z")

</div>

You may also want to watch this issue, which led to the creation of PushVectors:  
[https://github.com/JuliaLang/julia/issues/24909](https://github.com/JuliaLang/julia/issues/24909)
