Am Sun, 29 Dec 2013 22:45:35 +0000 schrieb "Vladimir Panteleev" <[email protected]>:
> [snip] > > 2. I don't understand the rationale behind the current semantics > of lookahead/lookbehind. If you want to e.g. peek ahead/behind to > find the first whitespace char, you don't know how many chars to > request. Wouldn't it be better to make these functions return the > ENTIRE available buffer in O(1)? Yeah, been there too. I guess after X years of programming chances are good you implemented some buffer with look-ahead. :) I use those primitives: ubyte[] mapAvailable() pure nothrow ubyte[] mapAtLeast(in ℕ count) See: https://github.com/mleise/piped/blob/master/src/piped/circularbuffer.d#L400 Both return a slice over all the available buffered data. mapAtLeast() also waits till enough data is available from the producer thread. The circular buffer is automatically extended if the producer wants to write a larger chunk or the consumer needs a larger window. (I was mostly focused on lock-free operation in not-starved situations and minimal bounds checking, so the code is a bit more sophisticated than the average circular buffer.) -- Marco
