3 ms·
If you're iterating, sure, use a vector. If you're pulling from a queue and doing a lot of processing, maybe an RPC -- does the ~70ns memory latency hit really
by tylerhou 4y ago
If you're iterating, sure, use a vector. If you're pulling from a queue and doing a lot of processing, maybe an RPC -- does the ~70ns memory latency hit really matter that much? Probably not.
- kibwen 4y agoWhy 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.
- pornel 4y agoIf you're pulling from a queue use a ring buffer.
- AstralStorm 4y agoSometimes. Depends on whether you are filling in a data buffer or trying to send an already calculated data buffer. A standard ring buffer does copies/fill. A ring buffer of pointers has similar performance characteristics to a linked list.
- Phelinofist 4y agoOT but does anyone know a general purpose ring buffer implementation for Java?
- grogers 4y agoLMAX disruptor: https://lmax-exchange.github.io/disruptor/user-guide/index.html https://lmax-exchange.github.io/disruptor/user-guide/index.h... It's used by log4j2 and several other java libraries and is quite solid. You can use it in blocking or polling modes, so it's quite generic depending on your latency requirements.
- speed_spread 4y agoUnfortunately log4j2 is no longer a shining example of good engineering, if you're trying to sell something... I'd prefer saying LMAX is / was used as the core of high frequency trading applications.