|
-
May 7th, 2010, 02:58 PM
#15
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.
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
|