Non-deallocating (permanently growing) extensible arrays

[Sorry for all errors of subject subcategory, ignorance of packages, etc. - this is my first post here]

I am looking for a package implementing a vector type where once space is allocated for an expansion (using, e.g., insert! or push!) it is not deallocated again if I later use pop! or delete, but keeps the space available for the next insert.

Basically, I need to maintain a very large number of vectors of changing length and I would like to avoid very many calls to alloc.

Anybody have a recommendation for something that does this?

Thanks in advance,

Sean Matthews

Welcome to the Julia forum. :slight_smile:

PushVectors explicitly does what you’re requesting, but I believe that in general Julia does not deallocate the underlying memory if you pop! off of or resize! a vector. The only real advantage to PushVectors is that it avoids a call into the runtime library at each usage of push!. There’s some discussion of the performance model of push! and friends scattered about on this forum that might be helpful.

https://github.com/tpapp/PushVectors.jl

2 Likes

Thanks for that. Very helpful.

Sean

Just use a normal Vector. As long as you don’t call sizehint! it will not reduce storage. PushVector is just an ugly hack to work around that push! is slightly slower than it has to be but unless that is a real bottle neck, just use normal Vector .

4 Likes

Yes, PushVectors is a joke gone too far. I added a warning about this.

EDIT also on nightly, Vector appears to be faster.

2 Likes

thanks