About the stack memory usage, in the past, I used a subfunction tagged with _Py_NO_INLINE to work on temporary stack but then drop it:
void function()
{
subfunction(); /* use temporary stack */
/* don't waste stack memory */
...
}
I'm not sure if such pattern could be used here for things like " PyObject *argsbuf[12];".
The problem is that argument parsing uses a lot of local variables allocated on the stack. In practice, it's more like:
void function(args)
{
int x;
parse_args(args, &x); /* use temporary stack */
/* don't waste stack memory */
...
}
I expect a long list of "&arg" where arg is a local variable of function(). Well, that's basically the design of the current PyArg_ParseTuple() function family :-)
PyArg_ParseTuple() does its stuff in private and uses more stack memory, but once PyArg_ParseTuple() returns, the memory on the stack is "released" just because we exited the function. |