This week I learned about a really useful—although specific—hack for bounded buffers: mirrored memory pages. Map N*2 pages with mmap then remap N and N+N regions to the same address. Now you can address contiguous memory in your ring buffer! Simple, fast, ergonomic.
Let that hardware MMU do the work for you
ヾ(@⌒ー⌒@)ノ