Do we have a "sizeforce!"?

Hello!

Reading in the help of sizehint!:

I notice how it is only a “suggestive” procedure and that it may do it. Is there a way to force it?

I know I can preallocate arrays my self. For less code complexity, I had hoped I could get away without doing that.

Kind regards

For Array, sizehint! does exactly that. We don’t have a way to force this in a generic way because we don’t really have an interface for it.

Not sure what you mean here - sizehint! does not change the actual useable size of an array, only how much memory it should reserve in the background:

julia> a = [1,2,3]
3-element Vector{Int64}:
 1
 2
 3

julia> length(a)
3

julia> sizehint!(a, 100)
3-element Vector{Int64}:
 1
 2
 3

julia> length(a)
3

This ends up making things like push! or append! faster as long as the length of the array doesn’t reach that requested capacity, because they don’t have to reallocate the array & copy the elements around under the hood.

Thank you, that makes a lot of sense :slight_smile: