Which is why you should:
- Preallocate the vector if you can guesstimate the size
- Use a vector library that won’t reallocate the entire vector on every single addition (like Rust, whose
Vec
doubles in size every time it runs out of space)
Memory is fairly cheap. Allocation time not so much.
Math is a language and as such it’s less pure than sociology. The universe knows no numbers, it knows no addition not division.