2 ms·
> Another simple trick is duplicating the buffer pointer field and buffer size field for consumer and producer Do you mean something like this? struct Inn
by 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.