On 1/28/18 12:35 AM, Paul Raulerson wrote:
This is a funny area to compare though, since on most platforms, C file access is always a binary stream. The application pretty much defines the way the file is treated - byte by byte, record by record, block by block, buffer size by buffer size, etc. To load an image for instance, it is pretty common to fstat() the image file to get its size, malloc() a buffer of the appropriate size, then do a single read() or fread() to populate the buffer. It is extremely efficient on most platforms, often due to the OS buffering.
Going even further, many platforms allow a file to be mapped into an application's address space. I work with an unmanaged C++ Windows application that does CreateFile() to open a file, GetFileSize() to get the size of the file and then CreateFileMapping() to map the file into the app's address space. At that point, the app doesn't need any I/O functions to process the file, it just accesses the contents as memory and lets the paging system handle the I/O. (And I think we like to believe that most operating systems go to great lengths to optimize paging logic.) *nix platforms have mmap() to provide similar functionality.

Reply via email to