Understanding C and Memory management

Source: Internet
Author: User

Understanding C and Memory management

The C program memory space is divided into the following 5 categories:

Stack Stack: stores data such as local variables and function parameters and grows downward (readable writable executable)

Heap Heap: to dynamically allocate memory usage, grow upward (readable writable executable)

b The SS SEGMENT:BSS segment is used to hold uninitialized global variables , uninitialized static variables, and two variables with initialization values of 0.

Data segment: Segment holds initialized global variable and initialized static variable (initialization value is not 0) (readable writable non-executable)

Code Segment/text segment: snippet for saving function and program code (readable executable not writable)

  1. C language Family
1) C:dennis Ritchie was developed at Bell Labs in 1972;Imperative language (imperative system language)]
2) C + +: Bjarne Stroustrup was developed at Bell Labs in 1979; is an imperative , object-oriented language that supports generics (generics)
3) C #: 2001, developed by Microsoft. is a multi-paradigm (MULTI-PARADIGM) programming language that supports imperative , function, generics, object-oriented, and memory management.
Note: imperative language, also known as mandatory language, describes the language of the computational process by specifying a sequence of executable operations and operations. Most of the languages we use (such as C,c+,java,c#,python, etc.) are imperative languages. Relative to it is the functional language (functional language), such as Haskell,lisp. Functional language is more like mathematics, and imperative language is closer to human thinking.

2. Typical characteristics of C:

1) compiled language (compiled language) (relative to interpreted language)

Compiled language: The program needs a special compilation process before execution, the program is compiled into machine language files, the runtime does not need to re-translate, directly run the results of the compilation is OK. Therefore high efficiency

Interpreted language: The program does not need to compile, the program is translated into machine language at run time, each time to be translated once. So the efficiency is lower.

2) command-style

3) Manual memory management

4) Use C when you need to address the following issues:

-Speed

-Memory

-Low-level features (low-level features), such as: mobile stack pointer, etc.

3. The level of memory abstraction (thinking from the memory point of view C ... )

Abstract Hierarchical programming language

--------------------------------------

Direct manipulation of memory assembly language

Accessing Memory c,c++

Memory Auto-Management java,c#,scheme/lisp,ml

4. C-Access memory: Heap

Heap is an area of memory used for dynamic memory allocation

1) Think of it as a huge array

2) Access by pointer (pointer)

3) The entire program can access the heap (if allowed by the operating system)

5. Artificial memory management: Heap

Objective:

1) allows the program to allocate memory for the current use

2) When the program finishes executing, it can free up memory for redistribution

Standard library for C language with malloc and free two functions support memory management

6. C Access to other memory: (Stack)

The C language is the compiler automatically allocates and recycles, for storing functions and their parameters, local variables and other memory areas

The C function will be assigned to the:

1) function is called in when it is transferred (pushed to stack)

2) function on return (POPEFD off the stack)

3) function can access all memory below the top of the current stay (so-called "top below" as shown below)

7. C language Compiler: It is recommended to use GCC, usually in Linux under the Gcc+vim write C program.

Understanding C and Memory management

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.