resize!(a::Vector, n::Integer) -> Vector
Resize a to contain n elements. If n is smaller than the current collection length, the first n elements
will be retained. If n is larger, the new elements are not guaranteed to be initialized.
BenchmarkTools.jl runs the function multiple times to give statistical results, in this case 10,000 samples. Only the first sample actually resized the array.
You’re calling resize! on the same value over and over, so it has no effect at all after the very first iteration. Thus the number of allocations per iteration (after the first) is exactly zero.
After the first resize!(x, 100) inside setup, the memory originally allocated by x=zeros(10000) is not freed actually, right? I want to figure out whether Julia has the same behaviour as C++ std::vector in this case.