Solved

fread vs. FSRead

Posted on 1997-01-22
1
259 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 88
move a line in eclipse 3 60
post4 challenge 28 83
building a service to accessed via telnet client, want colors ? 4 78
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now