CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Mixing istream and FILE*

    Quote Originally Posted by Lindley View Post
    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.

    Quote Originally Posted by Lindley View Post
    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.

  2. #17
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    1,342

    Re: Mixing istream and FILE*

    Quote Originally Posted by monarch_dodra View Post
    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

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured