2 ms·
Why impose that latency if you don't need to? It costs me nothing to reach for a vector instead.
by kibwen 4y ago
Why impose that latency if you don't need to? It costs me nothing to reach for a vector instead.
- AstralStorm 4y agoCosts you a dynamic memory allocation, code overhead and higher memory use. There are good reasons why std::array and plain arrays exist. Vectors are for when your data is unbounded, which is actually a risk most of the time. For truly big data, you want a special structure anyway.
- tylerhou 4y agoWithout extra work you can’t use a vector like a queue, and a circular buffer doesn’t necessarily support all types and/or preserve iterators on insert. Could use a deque, a blocked linked list. But IMO list is fine if it’s not clearly a bottleneck.