Does Julia push! require a copy of the entire array

Viewed 227

Looking into the code of push!, indicates that the array is grown the size of one element. Does the array logically grow the size of one element while the underlying storage stays the same as long as it is greater or equal than the required stored elements, and grown by creating a significantly larger storage and copying the entire array into it when the storage being full cannot accommodate the extra element? Or alternatively, does the array have to be recreated upon each push! operation.

function push!(a::Array{T,1}, item) where T
    # convert first so we don't grow the array if the assignment won't work
    itemT = convert(T, item)
    _growend!(a, 1)
    a[end] = itemT
    return a
end
1 Answers
Related