Python, the stack, and the heap

Rob Gaddi rgaddi at highlandtechnology.invalid
Mon Dec 17 14:30:24 EST 2018


I've been writing Python for good long while now without thinking too 
hard about this, but I just had a realization this weekend.

Back when the earth's crust was still cooling and we all rode dinosaurs 
to our jobs, local variables got allocated onto the stack, and dynamic 
memory from malloc or DIM explicitly allocated variables on the heap.

Python's objects all have a lifespan dictated by the continued existence 
of references to them and thus can transcend the lifetime of the current 
function in ways not known at translation time.  So am I right in 
thinking that all Python objects are out on the heap?  And that the 
references themselves may or may not wind up on the stack depending on 
what flavor you're running?

Answers to these questions have very little bearing on how I actually 
write Python, mind, but now I'm curious.


-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.



More information about the Python-list mailing list