For file reading, when to use filebuf

685 Views Asked by At

I'm going to be doing random-access reading from a read-only binary file. The interface to ifstream seems simpler than filebuf; but is there any use-case where filebuf would give better performance?

More details: I have a file of fixed-length (48-byte) records, and will be doing random-access reads in sequence -- read 1 record, process, read 1 record (from elsewhere), process, .... (Traversing a tree.) The file never changes. Since the records are fixed-length, I may later use a "character-type" that is the 48-byte record, but I don't imagine that has any performance effect.

1

There are 1 best solutions below

0
On

May be if you are on Linux may be using mmap would get around the whole problem of reading the file bit by bit.

Or boost memory mapped files? http://www.boost.org/doc/libs/1_52_0/libs/iostreams/doc/classes/mapped_file.html