Sponsored Content
Top Forums UNIX for Advanced & Expert Users Discussion on buffering of standard I/O library Post 302497881 by jim mcnamara on Friday 18th of February 2011 10:22:27 AM
Old 02-18-2011
The std C stdio calls work like this:

Code:
while data in file
  read data into buffer
  while data in buffer
    parse out a piece of the data:
      fgetc returns  one character
      fgets returns a line
  end
end

Stevens & Rago 'Advanced Programming in the UNIX Envrionment' has a chapter section on FILE I/O. Buffering is explained fully there.

One thing to note: modern disks have large buffers of their own which affects the performance of the stdio calls in C as well.
This User Gave Thanks to jim mcnamara For This Post:
 

We Also Found This Discussion For You

1. Solaris

Standard Template Library in Solaris 8.0

Hi Everybody, Can anyone guide me how to install SGI's STL Library on Solaris 8.0 ? Out of SGI's STL and STLPort, which third party STL is suitable, stable and thread-safe for UNIX Platform ? Please guide me over the above issue . Thanks & Regards Dinesh-Ahuja (0 Replies)
Discussion started by: md7ahuja
0 Replies
setbuffer(3C)						   Standard C Library Functions 					     setbuffer(3C)

NAME
setbuffer, setlinebuf - assign buffering to a stream SYNOPSIS
#include <stdio.h> void setbuffer(FILE *iop, char *abuf, size_t asize); int setlinebuf(FILE *iop); DESCRIPTION
The setbuffer() and setlinebuf() functions assign buffering to a stream. The three types of buffering available are unbuffered, block buffered, and line buffered. When an output stream is unbuffered, information appears on the destination file or terminal as soon as writ- ten; when it is block buffered, many characters are saved and written as a block; when it is line buffered, characters are saved until either a NEWLINE is encountered or input is read from stdin. The fflush(3C) function may be used to force the block out early. Normally all files are block buffered. A buffer is obtained from malloc(3C) upon the first getc(3C) or putc(3C) performed on the file. If the standard stream stdout refers to a terminal, it is line buffered. The standard stream stderr is unbuffered by default. The setbuffer() function can be used after a stream iop has been opened but before it is read or written. It uses the character array abuf whose size is determined by the asize argument instead of an automatically allocated buffer. If abuf is the null pointer, input/output will be completely unbuffered. A manifest constant BUFSIZ, defined in the <stdio.h> header, tells how large an array is needed: char buf[BUFSIZ]; The setlinebuf() function is used to change the buffering on a stream from block buffered or unbuffered to line buffered. Unlike set- buffer(), it can be used at any time that the stream iop is active. A stream can be changed from unbuffered or line buffered to block buffered by using freopen(3C). A stream can be changed from block buffered or line buffered to unbuffered by using freopen(3C) followed by setbuf(3C) with a buffer argument of NULL. RETURN VALUES
The setlinebuf() function returns no useful value. SEE ALSO
malloc(3C), fclose(3C), fopen(3C), fread(3C), getc(3C), printf(3C), putc(3C), puts(3C), setbuf(3C), setvbuf(3C) NOTES
A common source of error is allocating buffer space as an "automatic" variable in a code block, and then failing to close the stream in the same block. SunOS 5.10 13 May 1997 setbuffer(3C)
All times are GMT -4. The time now is 11:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy