Arm-linux Learning notes 3-linux memory management and file operations

Source: Internet
Author: User
Tags posix

Configuring a Linux system requires vim to be configured to help with our programming, the main configuration is as follows

In the/ETC/VIM/VIMRC file

The Display line number

Set number

The Auto Indent

Set Autoindent

The Smart Indent

Set Smartindent

"Four-grid tab at a time

Set tabstop=4

"One-four-grid

Set shiftwidth=4

"Parentheses match

Set Showmatch

The lower right corner shows the cursor status line

Set ruler

The file type detection

FileType on

Basically, these configurations are good.

Memory management is basically the memory of the application, the release of memory, the memory size has been applied to adjust these functions, such as under use

malloc is used to request memory

Free for Memory

Calloc request a piece of memory while initializing this piece of memory

ReAlloc The original memory size is incorrect, now request a new memory, while releasing the original memory

File system

Linux file system support two, one is the system call programming, there is a standard library programming, first said the standard library

In Linux ASCII programming, the file representation is the file file* type

    1. Standard input stdin keyboard standard input stdout standard output default is screen STDERR standard error default is screen
    2. Buffering, the Linux file system contains three buffering mechanisms, full buffering, the buffer is full before reading and writing to the physical device, row buffer, encounter newline characters ' \ n ' will be written to the physical device without buffering, direct read and write, not recommended

The SETBUF function can set the buffer size, the parameter is the file pointer and the buffer

Setvbuf set buffer size, buffered mode

3._IOFBF Full buffer _iolbf row buffer _IONBF unbuffered

4. Opening and closing of files

Fopen Open With Mode R Read W WB write and empty rb+ read and write open w+ write and empty

Fclose closing files

Read the file

Getc reads one byte, fails or returns EOF to the end

FGETC is the same as the previous one.

GetChar read in a byte from standard input

Putc

Fputc writes a Byte

Putchar writes a byte to the standard output

Fgets reading a line from a file

Gets reads a line from standard input

Fputs writes a line of string to the file, the Terminator must be nil

Puts output one line to standard output

Fread reads a block parameter is the buffer pointer data chunk size data block quantity file

Fwrite writes a parameter similar to the one, except that the action becomes a write

File location

The fseek parameter locates the offset start point for the file pointer

Seek_cur Current Location seek_end file end Seek_set file start

Ftell This function is also a file location, just rely on the data in the parameters to locate

Rewind set the file to the start position

The second type of file is programmed to invoke POSIX calls to the system

POSIX calls have a file descriptor for each file, an integer that represents an index value, and the default process can open up to 1024 files

Standard input file descriptor 0 standard output 1 standard error 2

Open the file

First, use POSIX to include the file

<sys/types.h>

<sys/stat.h>

<fcntl.h>

There is also a global variable errno

Open opening file, file path open flag (open also create file permissions)

Signs include o_rdonly o_wronly O_RDWR, etc.

Create file is not currently required, you can create it directly using open

Close file, parameter is file identifier

Read and Write file contents

Write

Read

File location

The Lseek parameter is basically consistent with the fseek, except that the file pointer is replaced with a file identifier

Modify the properties of a file that is already open

FCNTL related to file lock operations

Arm-linux Learning notes 3-linux memory management and file operations

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.