5 ms·
So don't spray tiny objects around. :) Keep them nicely tucked away in an arena. Vectors actually tend to create a spray of tiny objects... As opposed to a tru
by AstralStorm 4y ago
So don't spray tiny objects around. :) Keep them nicely tucked away in an arena.
Vectors actually tend to create a spray of tiny objects... As opposed to a true dynamic array which has limitations in resize. If you're lucky, they will keep a single dynamic array per vector. You're usually not this lucky with bigger data.
- josephg 4y agoIf you never free your objects, you may as well use an array anyway - it'll be much more simple. And if you use an arena with an object pool, you're back in cache miss territory. Vectors only "create a spray of tiny objects" if you have a vector-of-references or something like that. And even then, reading data requires 2 reads from memory (1 to read the pointer in the vector, and another to read the object). Finding item N in a linked list will require N reads (since you need to read each item before the target). Yes, resizing a vector is O(n). But every time I measure memcpy, it always goes faster than I expect. If you disagree, try to prove it with code. At least one of us will learn something that way.