Member-only story
CPU-Driven Circular Buffer
Did you know that you can delegate the wrap-around logic of a circular buffer to the hardware?
We can do this with virtual memory aliasing: by mapping multiple virtual addresses to the same physical memory location.
For context, we normally map virtual memory (memory in the application) 1 to 1 with physical memory (RAM).
Normal memory layout is 1 to 1
But we can force this map to something different. For example, we map several pages of our virtual memory to the same page in RAM.
Virtual memory aliasing we map many to the same physical address
The hardware takes care of wrapping around the data in the physical memory and we get to use the buffer normally, no index arithmetic, no wrap-around logic.
In the case of a circular buffer, conceptually:
I discovered this in Casey’s Computer Enhance course, and was compelled to test its performance, benchmarking it against a normal buffer.


![SBE Multicast Config Discovery [tutorial-ish]](https://miro.medium.com/v2/resize:fit:1358/format:webp/0*NuGojXJtt1akPwvh.png)








