Skip to main content
Engineering LibreTexts

17: Input/Output Buffering

  • Page ID
    19973
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    This chapter provides information regarding Input/Output (I/O) buffering. I/O buffering is a process that improves the overall throughput and efficiency of I/O operations. The general topic of I/O buffering is quite broad and can encompass many things including hardware, software, and data networking. This text addresses single buffer buffering for reading information from a file. While this is a very specific application, the general concepts regarding how and why buffering is performed apply generally to many different applications.

    High-level languages provide library functions that perform the I/O buffering and hide the associated complexity from the programmer. This is very desirable when programming. When working at a low-level, the buffering will need to be implemented explicitly (by us). The goal is to provide a detailed understanding of why and how buffering is performed in order to provide a more in-depth understanding of how a computer operates. This should help displace notions that such I/O is magic. And, of course, help us appreciate the compiler I/O library functions.

    • 17.1: Why Buffer?
      Accesses to secondary storage are significantly more expensive in terms of run-time than accesses to main memory. This would strongly encourage us to limit the number of secondary storage accesses by using some temporary storage, referred to as a buffer, in main memory.
    • 17.2: Buffering Algorithm
      The first step when developing an algorithm is to understand the problem. We will assume the file is already open and available for reading. For our buffering problem, we wish to provide a myGetLine() function to a calling routine.
    • 17.3: Exercises


    This page titled 17: Input/Output Buffering is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Ed Jorgensen.

    • Was this article helpful?