C language code memory Layout

Source: Internet
Author: User

It consists of the following three parts:

1) BSS segment

BSS segments are generally used to storeUninitialized global variablesMemory area. BSS is short for Block Started by Symbol. BSS segment belongsStatic Memory Allocation. The uninitialized data segment is generated only during the initialization phase, so its size does not affect the size of the target file.

The bss segment contains uninitialized global variables and static variables.

2) data Segment

Data segments are usually used to storeInitialized global variablesMemory area. Data Segment belongsStatic Memory Allocation.

  • The data segment consists of three parts: heap, stack, and static data zone.
  • Heap)
  • Stack)
  • Static Data zone: storesInitialized global variables, static variables, and constants.

3) text section

A text segment is usually used to store programs.Execute CodeMemory area. The size of this area is determined before the program runs, and the memory area isRead-Only. The code segment may also contain some read-onlyConstant variableSuch as string constants.

Eg:

Int a = 0; // The Global initialization zone (data) char * p1; // The Global uninitialized zone (BSS) main () {static int c = 0; // global (static) initialization zone (data) int B; // stack (data) char s [] = "abc"; // stack (data) char * p2; // stack (data) char * p3 = "123456"; // "123456 \ 0" is in the constant zone, and p3 is in the stack. (All in data zone) p1 = (char *) malloc (10); p2 = (char *) malloc (20 ); // The allocated 10-byte and 20-byte areas are in the heap area. (Data )}

Reference: http://www.nowamagic.net/librarys/veda/detail/2384

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.