Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6917105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:41:18+00:00 2026-05-27T09:41:18+00:00

I have the following question regarding C file I/O. At a physical level (harddrive),

  • 0

I have the following question regarding C file I/O.

At a physical level (harddrive), is it valid to assume that every fread(n_blocks, size, length,FILE fp) operation should cost one random access for the first page (block) and n-1 sequential accesses for the next blocks of that same buffer ??

I assumed this because the OS has so many processes that is mostly sure that one of them is also writing to or reading from a file between each fread of the local program and by that assumption the hard drive is positioned at another sector / cylinder.

is ok this assumption?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:41:19+00:00Added an answer on May 27, 2026 at 9:41 am

    Whether you assume that or not, this is a gross oversimplification of the reality.

    First thing first: you seem to think that the 3rd parameter (length) corresponds to the number of some discrete ‘access operations’. This is not the case. All fread does is to read size*length bytes; thus the following three calls do the exact same thing, as long as the multiplication doesn’t overflow:

    fread(n_blocks, size, length, fp);
    fread(n_blocks, size*length, 1, fp);
    fread(n_blocks, 1, size*length, fp);
    

    What actually happens, is that fread/fwrite will read and write to/from an internal buffer in the memory of your process. That buffer can be controlled with the setbuf/setvbuf functions. When the buffer is full/empty, they will forward the read/write to the operating system, which has its own file cache. If you are reading and the OS can’t find the portion of the file in the cache then your program will wait until the data is actually fetched from the drive. When writing, the data will be copied to the OS cache and reside there until the OS decides to write it to the drive, which may happen long after your program has closed the file and existed. In turn, today’s hard drives have their own internal caches which the OS may not even be aware of.

    For all practical purposes, you should not concern yourself with how many drive accesses each fread/fwrite call does. Just know that C, the OS, and the hardware underneath will do their best to provide the requested data as fast as possible. However, keep in mind that this entire stack is optimized for sequential access. So avoid jumping all around the file with fseek for no good reason.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following question and want help regarding that.I'm using Dropbox iOS SDK. Is
I have a question regarding the following code snippet I came across in one
I have a question regarding a race condition scenario. The question: Consider the following
I am new to chef and I have a question regarding the following. I
I have some questions regarding the following css that I found: html, body {
I have the following question. How can I print an output file line by
I'm developing a python application and have a question regarding coding it so that
I have a couple of question's regarding the following project. *Scott, Recently some developers
I have a question regarding the following code: while((c = getc(pFile)) != EOF) {
Yet another static question. I have read the following: What are static variables? file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.