FILE structure Body and buffer

Source: Internet
Author: User

file: A struct that contains the file name, file status, and the current location of the file for the C language contained in stdio.h.

Different compiler stdio header files have a slightly different definition of file, as defined in standard C:

int _flag;//read-write status flag bit int _file; Validation of file validity int _charbuf; Check the buffer condition and do not read int _bufsiz If no buffer is present; File size Char *_tmpfname;//temp file name};typedef struct _IOBUF file;

The general form of the definition file pointer is: file *FP; (file is the structure of the buffer, FP is a pointer to the file buffer)

We use fopen to return a file pointer (pointer to the file struct) for file manipulation.

Open files: File *fopen (char const *name,char const *mode);

File operating modes (mode):

R: Create file, read in

w: Create a file for writing. If the file already exists, delete the current content

A: Append, open or create file to write at end of file

r+: Open file for update (read and write)

w+: Create a file to update. If the file already exists, delete the current content.

A +: Append, open or create a file to update, write at the end of the file

Close files: int fclose (file *f);


Buffer (cache):

why to introduce buffers:

Because the computer operation of the buffer is much faster than the operation of the disk, in order to improve the efficiency of the computer, when we read the information from the disk, the first to put the read data in the buffer, the computer and then directly from the buffer data, and so on the buffer after the data taken out of the disk to read, This reduces the number of reads and writes to the disk.

Defined:

A buffer is an area of memory that is used between input and the CPU to cache data. It enables low-speed input and high-speed CPUs to work in a coordinated manner, avoiding low-speed input that occupy the CPU and freeing the CPU to work efficiently.

Type of buffer:

full buffering (_IOFBF): Actual I/O operations (disk files) when the standard I/O cache is filled

row buffering (_IOLBF): Performs a true I/O operation when a newline character is encountered in the input output. However, when the buffer is filled, the actual I/O operation is performed even without a newline character. (Standard input stdin and standard output stdout)

without Buffering (_IONBF): Without buffers, data is immediately read into or output to external memory files or devices. If the standard error stdeer



FILE structure Body and buffer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.