Memory in Python - Cornell University

Lecture 10

Memory in Python

Announcements For This Lecture

Reading

? Reread all of Chapter 3

Assignments

? Work on your revisions

? Want done by Sunday

? Survey: 445 responded

? Remaining do by tomorrow ? Avg Time: 6.5 hours ? STD Dev: 4 hours

? Assignment 2 also Sunday

? Scan and submit online

? Assignment 3 up Monday

9/24/15

Memory in Python

2

Modeling Storage in Python

? Global Space

Global Space

? What you "start with" ? Stores global variables ? Also modules & functions!

p

id2

Call Frame

? Lasts until you quit Python

incr_x

? Call Frame

? Variables in function call ? Deleted when call done

? Heap Space

? Where "folders" are stored ? Have to access indirectly

q

id2

id2 x 1.0

Heap Space

Point3

y 2.0 x 3.0

9/24/15

Memory in Python

3

Memory and the Python Tutor

Global Space

Heap Space

Call Frame

9/24/15

Memory in Python

4

Functions and Global Space

? A function definition...

? Creates a global variable (same name as function)

? Creates a folder for body ? Puts folder id in variable

def to_centigrade(x): return 5*(x-32)/9.0

Global Space

to_centigrade id6

Body

? Variable vs. Call

Heap Space

>>> to_centigrade >>> to_centigrade (32) 0.0

id6

function

Body

9/24/15

Memory in Python

5

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

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

Google Online Preview   Download