Implications of resize!

does the ability of resizing a Vector to a longer length implies that Vector is internally represented as something like a linked list, rather than a contiguous piece of memory???

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

julia> resize!(a, 4)
4-element Array{Int64,1}:
 1
 2
 3
 0

No, it’s contiguous memory. If you resize a vector grows the allocated memory block, reserving and exponentially growing block of memory so that append is amortized constant time.

2 Likes

thanks.

resize!() actually calls growend!(), which in turn calls a C routine (that I could not inspect further).

so, the behavior of growend!() would be something like: if there’s available memory after the end, use it; or if there’s none, copy to a new piece of contiguous memory.

is it correct? thanks.