cs31f08dis7

cs31f08dis7 - CS31: Introduction to Computer Science I Fall...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Discussion 3E Notes (Week 7, November 13) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 Digression: Memory Management (The purpose of this section is to help you develop some intuition that will help you understand how pointers work, which means you do not need to understand all the details here.) Every computer has a special “storage” called memory (you might have heard of RAM , and it’s what it is). When your program gets executed, it gets some amount of memory allocated for use. Some portion of it is used to store some useful data the computer needs, which we don’t have to worry about (labeled some data in the diagram below). Then some portion is used for main() function. Whenever we create a variable within main() , it is this region where the variable gets created. As we create more variables, this region expands its area. Now suppose I have the following program: int main() { func1(); // call func1() } void func1() { ... func2(); // call func2() } When func1() is called, a separate space for this call gets created, just above main() . (People who have consistently been coming to my section should identify this as the “box diagram” I used to draw when evaluating functions.) All variables used in func1() are created in this space. CS31: Introduction to Computer Science I Fall 2008 Week 7, Page 1/4 Memory some data main() int x double y some data main() string s Program 1 Program 2 func2() func1() func1() some data main() some data main() some data main() func1() some data main() some data main()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
When func2() gets called within func1()
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/20/2009 for the course CS CS31 taught by Professor Smallberg during the Fall '08 term at UCLA.

Page1 / 4

cs31f08dis7 - CS31: Introduction to Computer Science I Fall...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online