On 2/6/11 4:13 PM, Nick Sabalausky wrote:
"Andrei Alexandrescu"<seewebsiteforem...@erdani.org>  wrote in message
news:iimnm6$1m4a$2...@digitalmars.com...
On 2/6/11 12:42 PM, spir wrote:
Also: could a (truely) circular buffer help&  solve the above copy
problem, concretely?

Not if you want infinite lookahead, which I think is what any modern
buffering system should offer.


Agreed, but not everything always needs infinite lookahead. And sometimes
space guarantees are important.

If you don't use infinite lookahead you won't consume infinite memory. You stand to consume more memory though but I believe we're not supposed to optimize for that.

To implement O(n) buffering for n elements of lookahead you can use the circular buffer already present in std.range as backend, coupled with routines to replenish it. The disadvantage is that the client doesn't see true T[] buffers, it sees lookalike random-access ranges that use modulo operations for indexing. All in all this is an abstraction worth providing but not as general as discardFromFront() and appendToFront().


Andrei

Reply via email to