[quote name='e?dd' timestamp='1354050082' post='5004670']
Turn the input interface on its head. Rather than having an abstraction for buffer filling,
I don't understand. I have an abstraction for buffer filling?
[/quote]
I was asking that, really (though this wasn't obvious -- apologies). Again, had to guess.
I have a function that compresses input as it reads from a stream; if I already have the buffer, then I'm basically memory mapping. If I'm reading into a buffer through an abstract interface,
[/quote]
I'm saying that you don't have to (manually) read in to a buffer at all. You could argue memory mapping a file is doing this, but it should be doing it (near) optimally and it's handled for you, for the most part.
how is this different than using a buffered stream?[/quote]
There's no need for buffers! You can implement a buffered stream derived from the second interface if you want, but it's not necessary for (memory-mapped) files or raw memory, which seem to be your primary data sources.
If I use an abstract interface that could be a memory buffer, or a file, and I use functions to read from it, how is this different than the streams I already have?
[/quote]
Let me attempt to clarify by implementing the byte_source interface for a region of memory:
class memory_byte_source : public byte_source
{
public:
memory_byte_source(const unsigned char *begin, const unsigned char *end) : begin(begin) end(end) { }
byte_range next_range()
{
byte_range ret(begin, end);
begin = end;
return ret;
}
private:
const unsigned char *begin;
const unsigned char *end;
};
The first call to next_range() gives you the first and only byte_range (no copies, the range is the memory). The second call returns an empty range, telling you that the underlying data source is exhausted. The implementation for a memory mapped file will look very similar, except for the part where you create the mapping (in the constructor, perhaps).
The compression algorithm may of course have to be adapted for the new interface, but I don't imagine that would be too hard as you're now reading bytes through a pointer, regardless of the interface's implementation.