Memory in Python - Cornell University

Lecture 10

Memory in Python

Announcements For This Lecture

Reading

Assignments

? Reread all of Chapter 3

? Work on your revisions

¡ì Want done by Sunday

? Survey: 487 responded

¡ì Remaining do by tomorrow

¡ì Avg Time: 7.0 hours

¡ì STD Dev: 4.9 hours

? Assignment 2 also Sunday

¡ì Scan and submit online

? Assignment 3 up Monday

9/22/16

Memory in Python

2

Modeling Storage in Python

? Global Space

¡ì

¡ì

¡ì

¡ì

Global Space

What you ¡°start with¡±

Stores global variables

Also modules & functions!

Lasts until you quit Python

p

Call Frame

incr_x

? Call Frame

q

¡ì Variables in function call

¡ì Deleted when call done

id2

Heap Space

id2

? Heap Space

¡ì Where ¡°folders¡± are stored

¡ì Have to access indirectly

9/22/16

id2

Memory in Python

Point3

x

1.0

y

2.0

x

3.0

3

Memory and the Python Tutor

Heap

Space

Global

Space

Call Frame

9/22/16

Memory in Python

4

Functions and Global Space

? A function definition¡­

def to_centigrade(x):

¡ì Creates a global variable

(same name as function)

return 5*(x-32)/9.0

¡ì Creates a folder for body

Global Space

Body

to_centigrade id6

¡ì Puts folder id in variable

? Variable vs. Call

Heap Space

>>> to_centigrade

id6

function

>>> to_centigrade (32)

Body

0.0

9/22/16

Memory in Python

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download