4 ms·
Why not just use the % operator to make the memory wrap around? It seems so much simpler and less prone to errors. Ok, you'll need an extra ALU operation, but t
by amelius 12y ago
Why not just use the % operator to make the memory wrap around? It seems so much simpler and less prone to errors. Ok, you'll need an extra ALU operation, but these are cheap nowadays, especially if % is implemented by bit-masking.
Also, mmap may confuse the compiler, and to counter that you will have to add "volatile" everywhere, which very likely implies a performance hit anyway.
- ring_buffers 12y agoYou still need to modulo the index with this approach (otherwise you'd swiftly run into unmapped memory). The point is, what happens when you store items of different alignments in this buffer, you reach the end of it, and you need to store an item that will straddle both ends? You can manually write and read the bytes one by one for every access, you can pad out the remaining bytes then write the item at the beginning, or with a magic ring buffer, you can just write and read the data where it is and it will all work out.