-
May 7th, 2010, 02:58 PM
#16
Re: Mixing istream and FILE*
Originally Posted by Lindley
Incidentally, does the read/write mode work if you make a sync() call between them? I know normally you're supposed to either use fseek() (which is not supported by that implementation, that's the incomplete part) or fflush() between reads and writes.
I have no idea. To be honest, this problem is a bit over my knowledge, and everything I tried here was on a "let's see what happens if I write this" basis. According to cplusplus, sync does nothing by default. In this case, I think there might be a use for it in mixed read/write, but I would not know how to use it. Further more, the provided implementation is not complete. It does basic read/write , but it lacks all seek and get functions. They are probably not too hard to implement though.
Originally Posted by Lindley
Oh, and I'm sure I'll grab it---could be useful. However, a virtual function call for every single character strikes me as serious overkill nonetheless.
Well technically, when using a normal fstream or a stringstream, you are calling streambuf's and stringbuf's functions via virtual call too, so syncstream's overhead should be any more than standard streams. Unless they have special optimizations.
...
Sill, I say interface comes before implementation. syncstream seems like the correct solution to me. If after trying syncstream, you notice you have an io bottleneck, then I guess it could be time to look for another solution.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
-
May 7th, 2010, 06:05 PM
#17
Re: Mixing istream and FILE*
Originally Posted by monarch_dodra
Well technically, when using a normal fstream or a stringstream, you are calling streambuf's and stringbuf's functions via virtual call too, so syncstream's overhead should be any more than standard streams. Unless they have special optimizations.
streambuf and stringbuf maintain a buffer, so the virtual functions like overflow() only need to be called whenever the buffer is full. If the buffer size is, say, 512 bytes, this means overflow() only has to be called after every 512th character as opposed to every character. That can make a big difference.
Of course, if this is the only problem, nothing stops you from implementing a buffer for syncbuf too.
Old Unix programmers never die, they just mv to /dev/null
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|