3 ms·
Another simple trick is duplicating the buffer pointer field and buffer size field for consumer and producer (instead of having a single vector field). Paradoxi
by gpderetta 3y ago
Another simple trick is duplicating the buffer pointer field and buffer size field for consumer and producer (instead of having a single vector field). Paradoxically this makes the queue object smaller as it make use of the wasted padding used for cache alignment.
- rigtorp 3y agoIt might also be better for performance since the two cores can RFO the buffer pointer cache lines from each other.
- gpderetta 3y agoNeither producer or consumer ever writes into that line though, so it should stay in S state forever.
- xoranth 3y ago> Another simple trick is duplicating the buffer pointer field and buffer size field for consumer and producer Do you mean something like this? struct Inner { int\* data; size_t size; size_t cachedIdx; }; struct ringbuffer3 { // No vector<int> [...] here, saves a cache line alignas(64) std::atomic<size_t> readIdx_{0}; alignas(64) Inner writeInner; alignas(64) std::atomic<size_t> writeIdx_{0}; alignas(64) Inner readInner; // Constructor ... }; Am I understanding correctly? (edit: formatting)
- gpderetta 3y agoYes, except that you do not want to alignas writeInner and readInner. The size of your whole ringbuffer should be 128 bytes.