lua-users home
lua-l archive

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


When luaM_realloc() can't allocate the memory, it calls lua_error() 
which allocate a new string to display the error message, but if there 
isn't much memory luaM_realloc() calls again lua_error() and goes into 
loop until it reaches the "Stack overflow" error.
At the moment I solved it putting a counter in luaM_realloc(), checking 
it before calling lua_error() and exiting brutally from Lua at the 2nd 

Some questions on how to reduce the memory usage (with about 500 Kb for 
executable and data, isn't so much difficult to have memory problems):
1) At the start of my programs I load some my libraries written in Lua, 
but it is rare that I use all the functions of the libraries. Is there 
a simple method to know in runtime which functions are never used, so I 
can free them ? (analizing only the bytecode if possible, because the 
source couldn't be always available)

2) Is it possible to call automatically the garbage collection only 
when "it is really needed" ? Sometimes, Lua haven't enough memory but 
if I force a g.c. then it works fine. But I wouldn't fill my programs 
with collectgarbage() hoping to resolve the problem. For example, in 
Lua 3.2 I tried to call lua_collectgarbage() when luaM_realloc() can't 
allocate memory, but it corrupts the Lua stack. Is it safer to do in 
Lua 4.0 ?

3) Is it possible to reduce (not free all) the size of the MBuffer 
(lbuffer.c) every so often in a safe place ? I.e. in luaV_execute() or 
do_main(). This can free some memory allocated but no more used.

Thanks in advance.

>From lhf "Re: Re: Antwort: Re: Lua on DOS with 8086":
>>I added to Lua some functions. I.e.: read from/write to memory/port, 
>>call DOS interrupts, read in a table the directory contents.
>>For this reason, I suppose that I must change the name of the 
>>executable (I changed the Lua source, so I can't call it Lua, isn't 
>>it ?).
>Not at all. You haven't changed the language: you have only added a
>few functions -- ideally you did that i
dded it in a separated library.

>You'd have to change the name if you changed the lexer to accept
>hexadecimal constants or integers only, for instance. Or if you
>change the semantics of upvalues.
I changed a little lua.c and the lexer to accept constants with 
different bases (not only hexadecimal), for this reason I changed the 
name in Luna.