[Python-Dev] Tcl adept wanted for Stackless problem
Guido van Rossum
guido@python.org
Wed, 19 Jun 2002 11:07:36 -0400
> My big question is:
> When does Tcl use C stack entries as globals, which
> are passed as function arguments to interpreter calls?
It's a performance hack, just as stackless :-).
Tcl's interpreter data structure has a return value field which can
receive a string of arbitrary length. In order to make this
efficient, this is initialized with a pointer to a limited-size array
on the stack of the caller; when the return value is longer, a
malloc()'ed buffer is used. There is a little dance you have to do to
free the malloc()'ed buffer. The big win is that most calls return
short strings and hence you save a call to malloc() and one to free()
per invocation. This is used *all over* the Tcl source, so good luck
getting rid of it.
--Guido van Rossum (home page: http://www.python.org/~guido/)