By looking in the standard library documentation, it seems that for subclassing iostream, there are no other choice than implementing a streambuf class by overloading overflow and underflow.
In some cases, it is a good idea. But when you want to implement an iostream class for wrapping around an already buffered device (a compression library, a cryptographic library, etc...) it seems really not convenient, because:
- If you set a zero-sized buffer, for instance with setp(nullptr, nullptr), overflow will be called once per byte, even if the iostream::write function is called with large buffers, this seems poor regarding performance
- Implementing a fully functional buffer adds useless complexity if the underlying device is already buffered and accepts block writes, and if we just want to write a wrapper.
Did I miss something? Why isn't it possible to simply overload iostream write() and read()?