cs31s11dis7

cs31s11dis7 - CS31 Introduction to Computer Science I...

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

View Full Document Right Arrow Icon
Discussion 1H Notes (Week 7, May 13) TA: Brian Choi ([email protected]) 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 “func1() world” I used to draw when evaluating functions.) All variables used in func1() are created in this space. CS31: Introduction to Computer Science I Spring 2011 Copyright Brian Choi 2011. All rights reserved. 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 Document Right Arrow Icon
When func2() gets called within func1() , again, a separate space for it gets created. Once
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.

{[ snackBarMessage ]}

Page1 / 4

cs31s11dis7 - CS31 Introduction to Computer Science I...

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