Slide 5.15: System I/O and program buffers
Slide 5.17: Buffer.cpp
Home

Program Buffer Demonstrations


Take the the previous demonstrations as examples. Instead of entering the book information one by one, it is preferable that a file containing information of multiple books is downloaded to the system at one time. The following slides demonstrate how to use buffers to implement the data entry of multiple books at one time.

  Enter a Buffer Size and URL to Download the Inventory.

  A buffer size:  

  A book inventory (XML): 
 





    Password:                    

The goal is to reduce the number of disk I/Os as many as possible by giving a buffer size, which is the maximum number of characters can be read and stored for one disk I/O. This interface performs the following tasks:
  1. Reads the book information file whose path is specified on the interface by using the following two commands in the CGI Perl script:
      $inventory =~ s/\s*?http:\/\/([\w\.\~\/\-]*)[\S\s]*/http:\/\/$1/g;
      system( "lynx -dump -source '$inventory' > inventory.xml" );
    1. The first command is to remove some special meta characters from the URL for security reason.
    2. The second command downloads the book information file to a file named inventory.xml by using the text browser lynx.

  2. Fills the input buffer with a size specified on the interface.
  3. Assigns each record to a Book object and starts processing that object.
  4. Prints out the buffer contents, number of disk I/Os, and book titles.