lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Joshua Jensen wrote:
> 
/snip
> This presumes that people operate with Lua in a prescribed way.  My
> situation does not fit this.  Instead, it works with intertwined data,
> some of which is left on the stack for extended periods of time.  When
> the process is finished, the stack is, of course, clean, but it can
> require, depending on size of data, hundreds or thousands of stack
> entries (big databases).
> 
> You might say I am doing this incorrectly, but I am doing this very
> efficiently, because stack access is lightning fast, whereas
> lua_getref() access time has increased considerably since the Lua 4.0
> series.
/snip

Sorry, but I must say I disagree with you here. If there is a problem 
with the perfomance of lua_getref(), then that should be tackled. 
And, LUA 5 has the registry, which is very handy to store long-lived
C data in. I do not know anything about the performance of the registry,
but maybe the focus should be on improving the registry's performance. 

LUA is not FORTH. In Lua, like in many other programming 
languages, the stack is not ment to be a (semi-) permanent 
storage area, but rather a way to exchange data between functions. 
You only pop your arguments from the stack. When the function 
returns, only the results of the function are left on the stack. 
This is a Good Thing(tm).
 
In languages like C and C++, that type of stack hygene is enforced 
by the compiler. Lua, probably for performance reasons, does not 
enforce such a stack hygene, but that doesn't mean that we should 
abuse the stack for our own "dubious" purposes. 


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
bjorn.demeyer@pandora.be