2

I implemented a small read-only FUSE filesystem in C++ that reads the data from a certain multi-file archive. I used iostreams (actually boost::filesystem::ifstream) in order to read the files. Now I wonder if that was a wise decision.

First the error messages of iostreams are horrible (see another question by me) and I can't simply return the errno my file operations caused. But second I wonder if it may be better to use unbuffered IO when implementing a FUSE filesystem (not for reading the archive index but when reading the files - it's an uncompressed archive where files never are split to multiple archive files). Because the application reading the file will buffer if it wants to. Is this buffering just unnecessary overhead?

Also how fast are (boosts) iostreams? Well I can play WAV files from the mounted archive without problems, still I wonder if iostreams just add unnecessary overhead when I don't really need then (the only advantage they provide is that they automatically close the file when they go out of scope).

Community
  • 1
  • 1
panzi
  • 7,517
  • 5
  • 42
  • 54
  • Boost.Filesystem doesn't implement `fstream` as a whole, it only derives from your compiler's standard library implementation and overloads a few member functions. I.e., the speed is entirely dependent on your compiler's standard library implementation, not at all on Boost.Filesystem. – ildjarn May 20 '11 at 00:11
  • So how is the speed of gcc's iostreams? But the more important part of my question is: Would maybe unbuffered IO be better for a FUSE filesystem? Is buffered IO at this layer just unnecessary redundancy? – panzi May 20 '11 at 00:16
  • @panzi : I don't know the answers to any of those questions; that's why I posted a comment instead of an answer. :-] – ildjarn May 20 '11 at 00:17
  • GCC's `FILE` _is_ an iostream. Or more precisely, a streambuf. So there's no speed gain to be had by changing C++ I/O to C-style I/O. – MSalters May 20 '11 at 09:07
  • @MSalters Very interesting indeed. But with `FILE` I can get reasonable error messages and `errno` is set. Having `errno` is handy for a FUSE filesystem. Is there a way to get reasonable error messages using iostreams? – panzi May 20 '11 at 13:52
  • @MSalters: can you provide backup reference on that? I just made my parser 2x faster by using fopen/fread instead of ifstream. @panzi: you can consider `boost::shared_ptr(file, &::fclose)` – sehe May 24 '11 at 23:41
  • @sehe: `fread` is unformatted C-style I/O, `istream` is for formatted C++ style I/O. Either compare `fread` with `streambuf` or `fscanf` with `istream`. It's obvious that parsing is not free. – MSalters May 26 '11 at 09:23

0 Answers0