UT Dallas CS 4337 - #Sebesta ch05A Memory layout of C program - APUE7.6 (14 pages)

Previewing pages 1, 2, 3, 4, 5 of 14 page document View the full content.
View Full Document

#Sebesta ch05A Memory layout of C program - APUE7.6



Previewing pages 1, 2, 3, 4, 5 of actual document.

View the full content.
View Full Document
View Full Document

#Sebesta ch05A Memory layout of C program - APUE7.6

28 views


Pages:
14
School:
University of Texas at Dallas
Course:
Cs 4337 - Organization of Programming Languages

Unformatted text preview:

Advanced Programming in the UNIX Environment 3ed W Richard Stevens Stephen A Rago 2013 Addison Wesley 7 The Environment of Unix Process 7 6 Memory Layout of C Program 7 6 Memory Layout of C Program Historically a C program has been composed of the following pieces Text segment consisting of the machine instructions that the CPU executes Initialized data segment usually called simply the data segment containing variables that are speci cally initialized in the program Uninitialized data segment often called the bss segment named after an ancient assembler operator that stood for block started by symbol Stack where automatic variables are stored along with information that is saved each time a function is called Heap where dynamic memory allocation usually takes place 7 6 Memory Layout of C Program 7 6 Memory Layout of C Program Text Segment consisting of the machine instructions that the CPU executes Usually the text segment is sharable so that only a single copy needs to be in memory for frequently executed programs such as text editors the C compiler the shells and so on Also the text segment is often read only to prevent a program from accidentally modifying its instructions 7 6 Memory Layout of C Program Initialized data segment usually called simply the data segment containing variables that are speci cally initialized in the program For example the C declaration int maxcount 99 appearing outside any function causes this variable to be stored in the initialized data segment with its initial value 7 6 Memory Layout of C Program Uninitialized data segment often called the bss segment named after an ancient assembler operator that stood for block started by symbol Data in this segment is initialized by the kernel to arithmetic 0 or null pointers before the program starts executing The C declaration long sum 1000 appearing outside any function causes this variable to be stored in the uninitialized data segment 7 6 Memory Layout of C Program Stack where automatic variables are stored along with information that is saved each time a function is called Each time a function is called the address of where to return to and certain information about the caller s environment such as some of the machine registers are saved on the stack The newly called function then allocates room on the stack for its automatic and temporary variables This is how recursive functions in C can work Each time a recursive function calls itself a new stack frame is used so one set of variables doesn t interfere with the variables from another instance of the function 7 6 Memory Layout of C Program Heap where dynamic memory allocation usually takes place Historically the heap has been located between the uninitialized data and the stack 7 6 Memory Layout of C Program Figure 7 6 shows the typical arrangement of these segments This is a logical picture of how a program looks there is no requirement that a given implementation arrange its memory



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view #Sebesta ch05A Memory layout of C program - APUE7.6 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view #Sebesta ch05A Memory layout of C program - APUE7.6 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?