this post was submitted on 28 Apr 2024
495 points (96.8% liked)

Science Memes

9997 readers
2731 users here now

Welcome to c/science_memes @ Mander.xyz!

A place for majestic STEMLORD peacocking, as well as memes about the realities of working in a lab.



Rules

  1. Don't throw mud. Behave like an intellectual and remember the human.
  2. Keep it rooted (on topic).
  3. No spam.
  4. Infographics welcome, get schooled.


Sister Communities

Science and Research

Biology and Life Sciences

Physical Sciences

Humanities and Social Sciences

Practical and Applied Sciences

Memes

Miscellaneous

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 7 points 3 months ago* (last edited 3 months ago)

Which is why you should:

  1. Preallocate the vector if you can guesstimate the size
  2. 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.