Hacker News new | ask | show | jobs
by saagarjha 2484 days ago
> In C++ the std::vector type handles this by doubling the capacity when full.

Of course, the growth factor is implementation-dependent and I believe some compilers use smaller growth factors to improve performance.

1 comments

Th optimal growth factor is the golden ratio 1+sqrt(5) [1.618], but 2 is much faster to calculate.
Is calculating the new size really the bottleneck here?