Memory distribution under Linux

Source: Internet
Author: User

Sunday tells the memory distribution under 32-bit Linux

and the use of extern and static in C language.

Up to 1 g of memory is used as a system reservation, followed by space, near the 3G

Then down is the heap space, followed by the BSS, uninitialized static variable area

And then the RW data area.

Ro data area, primarily used as a storage string type

Next is the code snippet, also known as TXT body segment

0xFFFFFFFF

Kernel

0XBFFF FFFF

Stack

Heap

BSS area

RW data
RO data

Code snippet

0x00000000

The next step is to verify

1#include <stdio.h>2 3 Static intSg_init =Ten;4 Static intSg_uninit;5 6 7 intMain ()8 {9 Ten     intL_init =Ten; One     Static intInit_stack =Ten; A     Static intUninit_stack; -     Static intUninit_xxx =0; -      theprintf"Sg_init%p\n",&sg_init); -printf"Sg_uninit%p\n",&sg_uninit); -printf"L_init%p\n",&l_init); -printf"Init_stack%p\n",&init_stack); +printf"Uninit_stack%p\n",&uninit_stack); -printf"String,ro Data%p\n","Hello"); +printf"function%p\n", main); A  at}
View Code

The operation results are as follows

Sg_init 0x804a014
Sg_uninit 0x804a024
L_init 0xbfa0718c
Init_stack 0x804a018
Uninit_stack 0x804a028
String,ro Data 0x80485da
function 0x80483e4

Visible local variables are stored in the stack space because they are relatively close to the heap space 0xbf

The uninitialized static global variable and the static local variable are next to each other, and are higher than the initialized position, so the model is validated

The rodata is lower than the Rwdata segment, indicating that the static zone model is also correct

Similarly, the address of the code snippet conforms to the above model.

There is a less rigorous proof that the local variable stack space, how to exclude it is not in the heap space? How big is the stack space?

I don't understand it yet.

Memory distribution under Linux

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.