Lua C Stack Usage

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Lua C Stack Usage

Zachary P. Landau-4
Hello,

I'm currently using lua on an embedded system with limited resources
(ColdFire 5282 for the curious).  I was experiencing weird crashes
which I eventually traced back to stack overflows.  It seems that lua
uses up 6k or so of stack.  On systems without an MMU, this causes a
bit of a problem.

Most of that space is taken up by multiple copies of FuncState being
put on the stack.  I reduced the stack usage a bit by decreasing
MAXUPVALUES and MAXVARS, which affect the size of the FuncState
structure.  I suppose the FuncState could put on the heap, but I don't
want to go there if I don't have to.

I'm posting this for two reasons.  One, in case someone else runs into
a similar problem and is looking for a way to reduce stack usage.  And
two, to ask if anyone has any other tips for reducing stack usage.

-- 
Zachary P. Landau <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Lua C Stack Usage

Roberto Ierusalimschy
> I'm posting this for two reasons.  One, in case someone else runs into
> a similar problem and is looking for a way to reduce stack usage.  And
> two, to ask if anyone has any other tips for reducing stack usage.

The best approach is the one you already took: decrease MAXUPVALUES and
MAXVARS. For "usual" programs these can be 16-32 or even lower.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Lua C Stack Usage

Paul Du Bois
If you are using lua 4 you probably want to look at the "stackless"
patch, available from http://lua-users.org/wiki/LuaPowerPatches. I'm
not familiar with lua 5, so can't say if lua 5 is already stackless.

On Wed, 12 Jan 2005 16:43:51 -0200, Roberto Ierusalimschy
<[hidden email]> wrote:
> > I'm posting this for two reasons.  One, in case someone else runs into
> > a similar problem and is looking for a way to reduce stack usage.  And
> > two, to ask if anyone has any other tips for reducing stack usage.
> 
> The best approach is the one you already took: decrease MAXUPVALUES and
> MAXVARS. For "usual" programs these can be 16-32 or even lower.
> 
> -- Roberto
>

Reply | Threaded
Open this post in threaded view
|

Re: Lua C Stack Usage

Luiz Henrique de Figueiredo
> If you are using lua 4 you probably want to look at the "stackless"
> patch, available from http://lua-users.org/wiki/LuaPowerPatches. I'm
> not familiar with lua 5, so can't say if lua 5 is already stackless.

Lua 5 is "stackless". That patch was what prompted the introduction of
coroutines in Lua 5. --lhf