[Tutor] static PyObject * or non-static
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Sep 2 18:29:30 CEST 2004
> static PyObject *
> Noddy_name(Noddy* self)
> {
> static PyObject *format = NULL;
> PyObject *args, *result;
> I'm curious as to why the format PyObject * is made static.
One of the features of a static variable inside a function
is that it retains its value between function calls. Basically
static assigns storage on the heap rather than the stack. Most
function data is on the stack so that when a function call
ends all the data on the stack gets unwound and lost, but
the heap data persists.
> make everything static that can be?
No that will only waste memory. temporary variables within
functions should go on the stack so that they can be deleted.
Alan G.
More information about the Tutor
mailing list