>     okay, i tried. so why are globals bad and what problems
> do they solve?

now, my OS theory may be a bit rusty -- pls correct me where i'm
wrong, but from what i recall, one reason they're bad is because they
take up "unneeded" amount of memory.  in a traditional stack model --
think C, assembly, and how binaries are loaded into the OS for
execution: you have the TEXT section, which consists of the executable
code, the DATA section (sometimes divided up into 2 separate areas,
for zero- and nonzero-initialized/BSS data) for static variables,
global variables, etc., and the STACK and HEAP, as in this diagram
(drawn upside-down):

http://www.informit.com/content/images/chap3_0131429647/elementLinks/03fig01.jpg

the STACK is for tracking function calls (plus local variables
including parameters) while all dynamically-allocated memory comes
from the HEAP.  by increasing the size of your DATA section for
globals, it reduces the overall number of stack frames (function
calls) you can chain together, and likewise, you reduce the total
amount of memory that can be dynamically-allocated.  the STACK grows
upward while the HEAP grows downward, and memory issues occur when the
twain meet. if you have tons of globals, it increases the chance of
these types of collisions.

this GDB tutorial page is also useful in understanding these concepts:
http://www.dirac.org/linux/gdb/02a-Memory_Layout_And_The_Stack.php

the way it relates to Python is that Python is (of course) written in
C, and unless you're using the Stackless version of Python, each
Python function call results in one Python stack frame which results
in one C stack frame.

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to