4 ms·
For a similar end result (a circular buffer from which all returned ranges are contiguous) but without OS support for mmap()ing, there's also Bip Buffers[0]. I
by wrl 10y ago
For a similar end result (a circular buffer from which all returned ranges are contiguous) but without OS support for mmap()ing, there's also Bip Buffers[0]. I did an implementation in C [1] designed to be used for zero-copy IPC over shared memory (by way of having a structure with a flexible array member for the actual data).
[0]: http://www.codeproject.com/Articles/3479/The-Bip-Buffer-The-Circular-Buffer-with-a-Twist http://www.codeproject.com/Articles/3479/The-Bip-Buffer-The-...
[1]: https://github.com/wrl/wwrl/blob/master/src/bip_buffer.c https://github.com/wrl/wwrl/blob/master/src/bip_buffer.c
- versteegen 10y agoThanks for that. (Very long winded article though; you can skip to the diagrams.) Actually, bip buffers are so simple, I feel as if I've just learnt about linked lists for the first time!
- drudru11 10y agoThx for posting this - I have seen the other techniques, but never seen bip-buffers. Very cool
- loeg 10y agoThis has additional restrictions: * (Maximum) item size must be known in advance, and * Buffer items must be smaller than half the buffer size, and * If items are not suitably sized, buffer fragmentation may result There are also some cases where the padded size requirement may exceed available non-wrapped space with bip vs VRB or similar. Anyway, most OS support mmap(2) today :).
- wrl 10y agoYou're right on the second point and the third, though I reckon the fragmentation isn't appreciably worse than in a regular wrap-around circular buffer. Same goes for the first point. I'm keen to see examples where bip buffers exhibit particular issues relative to circular/ring buffers, however, and if you've got any then please send them along. The chief use-case for my bip buffer implementation is using a shared memory segment for inter-process communication, and adding mmap() for address mirroring on top of that just seems like a can of worms I'm not particularly interested in opening.