Solved

fread vs. FSRead

Posted on 1997-01-22
1
277 Views
Last Modified: 2013-12-26
Using CW 10 on a 604 based Mac-clone I have a C program that reads a binary file a few bytes at a time. The SIOUX implemented fread() function is almost 10 times faster than the Mac Toolbox function FSRead() at reading the whole file. I would have thought that fread() just calls FSRead() but apparently that's not the case. Is the problem just buffering? Does fread() have built in buffering that FSRead() lacks?
0
Comment
Question by:tlyons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
looker earned 100 total points
ID: 1291362
Yes fread does use an internal buffer for caching file reads. I'm not sure exactly what size the CW10 buffer is but it will be a minimum of 512 bytes and probably 2K or 4K. This buffer is filled on the first fread call, and subsequent fread calls actuall just transfer memory from the buffer to your storage. When the buffer is exhausted, or you position to somewhere in the file outside the buffer, another low level (FSRead call is made to re-fill the buffer).

FSRead on the other hand usesthe volume buffer for each block read into memory before it transfers it to your storage.

You could drastically improve performace by reading block size chunks from disk and reading through that buffer on your own. There is some extra programming involved, but that would also allow you to implement asynchronous I/O to make your code even more efficient. (You can parse one buffer while reading in another from disk.)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
only14 challenge 19 89
EvenOdd challenge 10 160
My project did see openJDK that I installed. What could be the problem 7 172
Work with App store 7 122
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question