lua-users home
lua-l archive

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




Roberto Ierusalimschy wrote:
 s=""
 for i=1,100000 do
   s=s.."x"
 end


Are you sure this is from "life.lua"? I didn't find it there...
The code I gave isn't; this is a simplification of life.lua's "draw" method:

  for y=1,self.h do
   for x=1,self.w do
      out=out..(((self[y][x]>0) and ALIVE) or DEAD)
    end
    out=out.."\n"
  end


Anyway, that code can really gives an "out of memory" error. This is not
a bug, but a limitation of the way Lua manipulates strings. (Java has
similar problems.)
I knew of this limitation (thanks to the wiki actually).

What makes me believe this is a bug is that with lua 5, life.lua dies after about 120 iterations, while it runs fine with lua 4. Similarly, the bit of code I gave runs fine (even though it takes time) with lua 4, but dies quickly with lua 5. Moreover, I can understand that concatenating strings this way is costly, but the corbage collector should reclaim unused memory... instead of that, memory usage grows, and once my 256 Mo of RAM are used the hard drive starts to trash and then the program dies...

Anyway, thanks for the reply and the info you gave.

Julien Cugniere