Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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)



Yes, except that you do not want to alignas writeInner and readInner. The size of your whole ringbuffer should be 128 bytes.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: